I am trying to write a script that will delete all comments and everything in between inside C files in my current directory. I've been using sed
, and this is what I have so far:
sed -i '/ * [^()] */d' *.c
This works when the comments are on the same line as an asterisk or backslash.
However it doesn't work when there is a commented line without a slash or asterisk.
I know sed goes line by line, I just don't know how to tell it to keep deleting until it sees a */
.
gcc -E test.c > test_p.c
. This will however include header files in the C-file. Otherwise I think you are better of with some kind of utility that is capable of parsing C-files, such as some kind of beautifier. – Kotte Apr 15 '13 at 16:03