简体   繁体   中英

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

 <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>

sed is not a good tool to handle xml. However since you are sure the format will be kept same. (see comments under Questions), you can try with this sed line:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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