I have a script that searches for a string and replaces it via the sed command. If that string contains special characters, the script will escape them (except for the slash because it's my current delimiter for sed and the column because it marks the string on the bash line).
Here it goes:
raw_searchstring='SearchForThis';
raw_replacementstring='ReplaceWithThis';
#Escape special characters:
quoted_searchstring=$(printf %s "$raw_searchstring" | sed 's/[][()\.^$?*+]/\\&/g');
quoted_replacementstring=$(printf %s "$raw_replacementstring" | sed 's/[][()\.^$?*+]/\\&/g');
find ./ -type f -exec sed -i -r "s/$quoted_searchstring/$quoted_replacementstring/" {} \;
I tested this on Ubuntu and it worked just fine.
However, I need to run the script on a AIX system. Since it does not support in-line editing with sed -i I tried the following, as suggested on a similar question here (AIX's sed - in place editing):
find ./ -type f -exec sed -r 's/$quoted_searchstring/$quoted_replacementstring/' infile > tmp.$$ && mv tmp.$$ infile {} \;
This is where I get the error
find: missing argument to `-exec'
so I tried to pass more than one -exec statement to find
with this line:
find /home/tobias/Desktop -type f -exec sed -r 's/$quoted_searchstring/$quoted_replacementstring/' infile > tmp.$$ {} \; -exec mv tmp.$$ infile {} \;
that doesn't work either:
sed: can't read infile: No such file or directory
I am not sure what I did wrong. Can you help me fix this line of code or point me in the right direction?