[英]SED to replace text inside quotes
Assuming I have a text file where some lines are of this format: 假设我有一个文本文件,其中某些行是这种格式的:
%attr(750,user1,group1) "/mydrive/mypath1/mypath2\winpath1\winpath2\file.xml"
What I wanna achieve is: 我想要实现的是:
\\
to /
\\
到/
What is the proper syntax for sed utility? sed实用程序的正确语法是什么?
awk can do the job easily: awk可以轻松完成这项工作:
awk -F '"' '/^%attr/ {gsub(/\\/, "/", $(NF-1))} 1' OFS='"' file
To change the original file: 更改原始文件:
awk -F '"' '/^%attr/ {gsub(/\\/, "/", $(NF-1))} 1' OFS='"' file > _tmp && mv _tmp file
您可以尝试使用此sed '/\\%attr/{s/\\\\/\\//g}'
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.