I have a file with contents
abc dbw ;\
xxx{ sample test }
bewolf \
bewolf
test
I need to check for
xxx{ sample test }
bewolf
and comment out these line like
/*xxx{ sample test }
bewolf*/
I have tried with grep but grep searches for string. As Dash script does not have arrays it makes it an even tougher job.
I was trying to get the starting and end index so that I can cut out that section using head and tail.
Any other ideas like using sed and awk are welcomed.
To be more general, I need to comment one macro in a C file using a Bash script.
If multiple end comments don’t bother you, you could use a simple
sedlike this:sed -e "s%^xxx{ sample test }$%\/\*&\*\/%" -e "s%^bewolf$%\/\*&\*\/%" file.txtinput:
output:
Add the
-iflag if you would like to overwritefile.txtdirectly.