Find and replace a text in a file. Find word is same all the time and replacing string varies all the time
I am trying a simple sed script (test.sh) to achieve this which uses a parameter(a long string with special characters):
sed -i "s/#####REPLACE#####/$1/g" file.txt
The result should replace #####REPLACE#####
with the parameter that I pass to the script test.sh
.
The parameter varies all the time and contains a lot of special characters (something like this):
"abc"/def:-/ghi$jklmno-pqrblah..blah..very..long..string
The command I am trying is:
./test.sh "abc"/def:-/ghi$jklmno-pqrblah..blah..very..long..string
It gives out the below message:
sed: -e expression #1, char 25: unknown option to `s'
I have many files (e.g. file1.txt
, file2.txt
, file3.txt
) with the same common text #####REPLACE#####
to be replaced by the same parameter "abc"/def:-/ghi$jklmno-pqrblah..blah..very..long..string
.
Any suggestions?