Friday, 9 August 2013

How to remove comments from preceded by #, but preserving #include and #!

How to remove comments from preceded by #, but preserving #include and #!

I need to remove the comments section on piece of code for diff purposes.
I use grep and sed to remove all lines starting with #, // and ;, as well
as multiple lines enclosed by /* and */.
One issue is that this rule also removes the lines starting with #include
and #!/bin/whatever which are valid code statements.
Is there a way to preserve the lines containing #include and #! at the
start but remove the rest of the lines starting with # using either grep
or bash.
Thanks in advance for your response.

No comments:

Post a Comment