使用Shell脚本编辑xml文件时的XML文件结构 [英] XML file structure while editing xml file with shell script
问题描述
我正在尝试使用Shell脚本编辑xml文件。我找到了一些帮助,例如此。但是我的XML文件的结构几乎没有什么不同。这是我的XML文件的示例:
I am trying to edit a xml file wi9th a shell script. I have found some help like this. But the Structure of my XML file is little different. This is a example of my XML file:
<Code>
<Type name="abc">this is ABC</Type>
<Type name="xyz">this is XYZ</Type>
</Code>
在这里,我要获取这是ABC
和这是XYZ
文本,然后像这样附加字符串:
Here I want to get the this is ABC
and this is XYZ
text and then append a String with them like this:
<Code>
<Type name="abc">this is ABC EDITED</Type>
<Type name="xyz">this is XYZ EDITED</Type>
</Code>
我可以编辑'abc'
xmlstarlet ed --inplace -u "/Code/Type[@name='abc']/@name" -v abc_edited ./abc.xml
但是如何编辑'这是ABC'
字符串,其中'这是ABC'
可以是未知的吗?
But How can I edit the 'this is ABC'
String where 'this is ABC'
can be anything unknown?
推荐答案
可以使用awk
Content =(cat abc.xml | awk -f'[{}]'' / Type name = abc /'{print $ 3} | sed's /这是ABC /这是ABC EDITED / i')
Content = (cat abc.xml | awk -f '[{}]' '/Type name="abc"/'{print$3} | sed 's/this is ABC/this is ABC EDITED/i')
这篇关于使用Shell脚本编辑xml文件时的XML文件结构的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!