Reputation: 75
I'm trying to replace string #########
to $
in all files in $HOME/findreplace/
directory with below statements but I'm getting sed: Function s_#########_ cannot be parsed.
error.
Thanks in advance for you help.
for file in $HOME/findreplace/*.*
do
sed -e "s_#########_$_g" $file> /tmp/tempfile.tmp
mv /tmp/tempfile.tmp $file
echo "Modified: " $file
done
Upvotes: 1
Views: 714
Reputation: 47267
You can do:
for file in $HOME/findreplace/*.*
do
sed -i 's/#########/\$/g' "$file"
echo "Modified: $file"
done
Explanation:
/
instead where you had _
before to separate the pattern to match and pattern to replace.\
to escape the $
char-i
option to sed
to do in-place editing, so you can avoid having to use a temp file.$file
) in double-quotes.Upvotes: 2