Remove multi-line comments

Here’s one way using GNU sed. Run like sed -rf script.sed file.txt

Contents of script.sed:

:a
s%(.*)/\*.*\*/%\1%
ta
/\/\*/ !b
N
ba

Alternatively, here’s the one liner:

sed -r ':a; s%(.*)/\*.*\*/%\1%; ta; /\/\*/ !b; N; ba' file.txt

Leave a Comment