我无法替换双反斜杠后跟引号 \\'
在 sed 中。这是我当前的命令
echo file.txt | sed "s:\\\\':\\':g"
上面的命令不仅替换了
\\'
与 \'
它也取代了 \'
与 '
我怎么能只替换完全匹配?
输入:
'one', 'two \\'change', 'three \'unchanged'
预期的:
'one', 'two \'change', 'three \'unchanged'
实际的:
'one', 'two \'change', 'three 'unchanged'
最佳答案
$ sed "s/\\\\\\\'/\\\'/g" file
'one', 'two \'change', 'three \'unchanged'
Here is a discussion on why sed needs 3 backslashes for one
关于regex - 使用 sed 替换双反斜杠后跟引号 (\\')?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30826144/