How would I replace a single quote (') with a backslash then single quote (\') using sed?
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
Try the following:
sed -e s/\'/\\\\\'/g input > output
To prove that this works:
echo "Hello 'World'" | sed -e s/\'/\\\\\'/g
The output should be:
Hello \'World\'