I'm trying to replace a string inside a text file using sed
. This string could contain any special character like .
, /
, $
, etc. However, I'm interested to replace such a string literally, that is to not interpret .
, /
, $
, etc. as special characters.
So, the simple instruction
sed -i s|$old|$new| "$path_to_file"
doesn't work as I expect if I want to replace 20.8
with 20.9
for example.
Of course, before starting the script that uses this sed
, I don't have any idea where the special characters will be placed by the user.
Is there a way to do this with sed
or any other tools (perl
, awk
, etc.)?
Thanks!