How would I replace a single quote (') with a backslash then single quote (\') using sed?
sed s/\'/\\\'/
won't work because you never get to write the literal .
sed ":a;N;s/\'/\\'/g" <file1 >file2
won't work because the backslash will no longer escape the quote, it get's treated like a regex quote.
just quote the replacement
$ echo \' | sed s/\'/"\\\'"/
$ \'
e.g
$ cat text1
this is a string, it has quotes, that's its quality
$ sed s/\'/"\\\'"/ text1 > text2
$ cat text2
this is a string, it has quotes, that\'s its quality
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