I am programming in bash to modify a large collection of files built in C and I need to comment out segments of information (/* */).
The line reads: *action.acroread: {APPMGR_acroread("blah.pdf");}
I want to insert a comment string "/* */" before the {APPMGR... and close it at the end of the line.
Currently I have the code
for i_file in $file_list[@]}; do
sed -i '/^*action.acroread/ s|.*|/* & */|' $i_file
...
done
Which inserts a /* at the beginning of the line and a */ at the end of the line, commenting out the whole line. It also prevents multiple commenting blocks from being added in case I run the script multiple times.
What I need to do is to add /* in front of {APPMGR_acroread(“blah.pdf”);} and */ at the end of the line, so the end result should look like
*action.acroread: /* {APPMGR_acroread(“blah.pdf”);} */
What I have so far is
sed -i ‘/^action.acroread/ s|.{APPMGR_acroread|/* & */|’ $i_file
This results in the following output
*action.acroread:/* {APPMGR_acroread */(“blah.pdf”);}
In addition, running it a second time causes a second pair of comment blocks to appear
*action.acroread:/* /* {APPMGR_acroread */ */(“blah.pdf”);}
The blah.pdf is different inside every file. (blah.pdf, blah2.pdf, blah3.pdf, etc)
How can I modify the code to only comment block the second half of the line in addition to preventing multiple comment blocks when running the script multiple times? Thanks.