How would you delete all comments using sed from a file(defined with #) with respect to \'#\' being in a string?
This helped out a lot except for the string portion.
This might work for you (GNU sed):
sed '/#/!b;s/^/\n/;ta;:a;s/\n$//;t;s/\n\(\("[^"]*"\)\|\('\''[^'\'']*'\''\)\)/\1\n/;ta;s/\n\([^#]\)/\1\n/;ta;s/\n.*//' file
/#/!b if the line does not contain a # bail outs/^/\n/ insert a unique marker (\n)ta;:a jump to a loop label (resets the substitute true/false flag)s/\n$//;t if marker at the end of the line, remove and bail outs/\n\(\("[^"]*"\)\|\('\''[^'\'']*'\''\)\)/\1\n/;ta if the string following the marker is a quoted one, bump the marker forward of it and loop.s/\n\([^#]\)/\1\n/;ta if the character following the marker is not a #, bump the marker forward of it and loop.s/\n.*// the remainder of the line is comment, remove the marker and the rest of line.