sed -i 's:\(.*\)/[*]\(.*\)[*]/:\1 // \2:' FILE
this converts each line as follows:
aaa /* test */
to a line like this:
aaa // test
If you have more comments on one line, you can apply this more complex parser, which converts the line, for example:
aaa bbb ccc
in
aaa bbb ccc
sed -i ':rs:\(.*\)/[*]\(.*\)[*]/\(.*\):\1\3 //\2:;tr;s://\(.*\)//\(.*\)://\2\1:;tr' FILE
A more complicated case is when you have comments inside lines in a line, for example, in call("/*string*/") . To solve this problem, there is a script c-comments.sed :
s:\(["][^"]*["]\):\n\1\n:g s:/[*]:\n&:g s:[*]/:&\n:g :r s:["]\([^\n]*\)\n\([^"]*\)":"\1\2":g tr :x s:\(.*\)\n/[*]\([^\n]*\)[*]/\n\(.*\)$:\1\3 // \2: s:\(.*\)\n\(.*\)//\(.*\)//\(.*\):\1\n\2 //\4\3: tx s:\n::g
You save this script to the c-comments.sed file, and you call it like this:
sed -i -f c-comments.sed FILE
source share