Reputation: 263
I want to comment a line where ever this condition comes
if(a & b)? c:d;
so i have seen one script,but its not working.
for f in var.c; do
cat $f | sed 's@if(a & b)\(.*\)$@/*\1 */@' > converted-files/$f
done
Can any one tell me the better script than this which will work for my circumstance.
Upvotes: 0
Views: 80
Reputation: 753525
You really shouldn't be using cat
. Your code fragment is not valid C, either, but that may be a good reason for commenting it out.
for f in var.c
do
sed 's@if(a & b).*$@/*&*/@' $f > converted-files/$f
done
You can add spaces around the comment markers if you prefer, but symmetry suggests either 0 or 2 spaces in total, not just 1 as in your script.
Upvotes: 0
Reputation: 123458
Your sed
expression is written to include only the part after the ternary operator. Try:
sed 's@if(a & b).*$@/* & */@'
That said, I'm not sure if you really want to use regex to comment out code.
Upvotes: 1