使用以下文本文件test.txt
:
{\x22order\x22:\x22161332\x22,\x22name\x22:\x22chiller\x22,\x22code\x22:\x22chiller\x22}
{\x22order\x22:\x22161332\x22,\x22name\x22:\x22chiller\x22,\x22code\x22:\x22chiller\x22}
{\x22order\x22:\x22161332\x22,\x22name\x22:\x22chiller\x22,\x22code\x22:\x22chiller\x22}
如何在Sed中用单引号替换\x22
的出现?
我已经无济于事:sed -i "s#\x22#'#g" test.txt
答案 0 :(得分:2)
您需要转义反斜杠以使其原义,并且需要使用'\''
来表示单引号中的单引号(除非绝对必要,否则它们都应为字符串)或脚本
$ sed 's/\\x22/'\''/g' file
{'order':'161332','name':'chiller','code':'chiller'}
{'order':'161332','name':'chiller','code':'chiller'}
{'order':'161332','name':'chiller','code':'chiller'}