简体   繁体   English

通过shell脚本在所有情况下从xml文件中选择并替换字符串

[英]Select and replace a string from an xml file in all occurences via shell scripting

I need to replace a string in a xml file in all occurences using shell scripting 我需要使用shell脚本在所有情况下替换xml文件中的字符串

 <field> <name>CC</name> <displayType>USER</displayType> <displaySize>25</displaySize> <displayLines>1</displayLines> </field> 

I need to replace <name>CC</name> in all occurences in the xml file with <name>Carbon Copy</name> 我需要用<name>Carbon Copy</name>替换xml文件中所有出现的<name>CC</name> <name>Carbon Copy</name>

sed is not a good tool to handle xml. sed不是处理xml的好工具。 However since you are sure the format will be kept same. 但是,由于您确定格式将保持不变。 (see comments under Questions), you can try with this sed line: (请参阅问题下的评论),您可以尝试使用以下sed行:

sed -i 's#<name>CC</name>#<name>Carbon Copy</name>#g' file

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

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