I am having trouble figuring out how to use sed
to search and replace strings containing the /
character in a text file /etc/myconfig
.
For instance, in my existing text file, I have:
myparam /path/to/a argB=/path/to/B xo
and I want this replaced by:
myparam /path/to/c argB=/path/to/D xo
I attempted doing this in bash:
line='myparam /path/to/a argB=/path/to/B xo'
line_new='myparam /path/to/c argB=/path/to/D xo'
sed -i 's/$line/$line_new/g' /etc/myconfig
But nothing happens.
Attempting
grep -rn "$line" /etc/myconfig
does return me 'myparam /path/to/a argB=/path/to/B xo'
though.
What's the correct way to express my sed
command to execute this search and replace and correctly deal with the /
command? (I reckon that the /
character in my strings are the ones giving me the problem because I used a similar sed
command to search and replace another line in the text file with no problems and that line does not have a /
character.