regex - 使用 sed 替换双反斜杠后跟引号 (\\')?

标签 regex shell unix sed

我无法替换双反斜杠后跟引号 \\'在 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/

相关文章:

shell - 使用函数用 bamboo 重新启动 tomcat 实例

regex - 快速正则表达式问题

javascript - RegExp.exec 不返回全局结果

python - 使用正则表达式排除引号内的案例

shell - 为什么 "echo 123 > a.txt b.txt"只创建一个文件?

linux - AIX 上的 CPU 用户时间和系统时间

mysql - 如何检索一列中包含五位数字的所有行

bash - shopt 在 shell 函数中不起作用

android - 在 adb shell 中存在的 sh 的帮助下在 android 设备中运行的脚本文件

c - 在 C 中删除原始文件的符号链接(symbolic link)