Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
假设我有一个文本文件,其中一些行是这种格式:
%attr(750,user1,group1) "/mydrive/mypath1/mypath2\winpath1\winpath2\file.xml"
我想要实现的是:
\
/
sed实用程序的正确语法是什么?
awk 可以轻松完成这项工作:
awk -F '"' '/^%attr/ {gsub(/\\/, "/", $(NF-1))} 1' OFS='"' file
要更改原始文件:
awk -F '"' '/^%attr/ {gsub(/\\/, "/", $(NF-1))} 1' OFS='"' file > _tmp && mv _tmp file
你可以试试这个sed '/\%attr/{s/\\/\//g}'
sed '/\%attr/{s/\\/\//g}'