Reputation: 115
I have a bash script that I need to insert a ' into it after a ( and before a )
MYSTRING(FOO_1234_BAR)
needs to be
MYSTRING('FOO_1234_BAR')
From what I've been reading, I should be using sed, but I'm having trouble with the syntax.
Thank you.
Upvotes: 1
Views: 1300
Reputation: 133760
EDIT: Adding one more solution simple one of sed
if Input_file is same as sample shown.
sed "s/(/&'/;s/)/'&/" Input_file
Following sed
may help you on same.
sed "s/\([^(]\)(\([^)]*\))/\1('\2')/" Input_file
Output will be as follows.
MYSTRING('FOO_1234_BAR')
In case you want to save output into Input_file itself then use sed -i
or in case you need to take backup of Input_file and save the output into Input_file itself then use sed -i.bak
in above command.
Upvotes: 2