如何使用 sed 将单引号 (') 替换为反斜杠,然后替换单引号 (\')?
sed s/\'/\\\'/
行不通,因为你永远无法写出文字。
sed ":a;N;s/\'/\\'/g" <file1 >file2
不起作用,因为反斜杠将不再转义引号,它会被视为正则表达式引号。
只需引用替代品
$ 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
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)