如何使用sed替换带有反斜杠然后单引号(\')的单引号(')?
sed s/\'/\\\'/
Run Code Online (Sandbox Code Playgroud)
不会起作用,因为你永远不会写文字.
sed ":a;N;s/\'/\\'/g" <file1 >file2
Run Code Online (Sandbox Code Playgroud)
不起作用,因为反斜杠将不再逃避引用,它被视为正则表达式引用.
只是引用替换
$ echo \' | sed s/\'/"\\\'"/
$ \'
Run Code Online (Sandbox Code Playgroud)
例如
$ 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
Run Code Online (Sandbox Code Playgroud)