I have this command:
sed -i "s/a:b/b:c/g" file.txt
(in English: replace "a:b" with "b:c" in file.txt)
This doesn't work because of the colons in the subsitution text. How should I re-write the command?
The s command is probably the most important in sed and has a lot of different options. Its basic concept is simple: the s command attempts to match the pattern space against the supplied regexp; if the match is successful, then that portion of the pattern space which was matched is replaced with replacement.
When in doubt, echo the command: echo sed "s/\//\\\//g" -> sed s/\//\\//g . Btw you can use something else for sed, like 's@/@\\/@g' .
In case you want be safe , you can escape the :
colon
sed -re "s/a\:b/b\:c/g" temp.txt
This worked for me:
-->cat 1
a:bLINE1
a:bLINE2
-->cat 1 | sed 's/a:b/b:c/g'
b:cLINE1
b:cLINE2
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With