简体   繁体   English

使用AWK替换一些特殊代码

[英]Using AWK to replace some special codes

lets say I have a file called somedata.txt, I am trying to replace: 可以说我有一个名为somedata.txt的文件,我正在尝试替换:

\\" \\”

with

"

ie removing the \\ I am trying to do this using AWK. 即删除\\我正在尝试使用AWK做到这一点。 Can you please help? 你能帮忙吗?

You will need to escape both characters \\ and " like shown below 您将需要转义两个字符\\"如下所示

awk '{gsub("\\\\\"", "\"")}1' somedata.txt

Or if you can use sed it becomes simpler 或者,如果您可以使用sed它将变得更加简单

sed 's/\\"/"/g' somedata.txt

sed also allows inplace editing (flag -i ) to update original files sed还允许就地编辑(标志-i )来更新原始文件

sed -i 's/\\"/"/g' somedata.txt

You can also open file in vim editor and try this: Press esc and then 您也可以在vim编辑器中打开文件,然后尝试以下操作:按esc,然后按

:%s_oldString_newString_g

For your case, it's 对于你的情况

:%s_\\\"_\"_g

Since " and \\ are special characters, you need to add a \\ before the chars to make the command execute. 由于“和\\是特殊字符,因此需要在字符前添加\\以使命令执行。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM