[英]XML file structure while editing xml file with shell script
I am trying to edit a xml file wi9th a shell script. 我正在尝试使用Shell脚本编辑xml文件。 I have found some help like this . 我发现像一些帮助这个 。 But the Structure of my XML file is little different. 但是我的XML文件的结构几乎没有什么不同。 This is a example of my XML file: 这是我的XML文件的示例:
<Code>
<Type name="abc">this is ABC</Type>
<Type name="xyz">this is XYZ</Type>
</Code>
Here I want to get the this is ABC
and this is XYZ
text and then append a String with them like this: 在这里,我想得到的this is ABC
和this is XYZ
文本,然后像这样附加字符串:
<Code>
<Type name="abc">this is ABC EDITED</Type>
<Type name="xyz">this is XYZ EDITED</Type>
</Code>
I can edit the 'abc'
like this: 我可以这样编辑'abc'
:
xmlstarlet ed --inplace -u "/Code/Type[@name='abc']/@name" -v abc_edited ./abc.xml
But How can I edit the 'this is ABC'
String where 'this is ABC'
can be anything unknown? 但是,如何编辑'this is ABC'
字符串,其中'this is ABC'
可能是未知的?
This could be done using awk 这可以使用awk完成
Content = (cat abc.xml | awk -f '[{}]' '/Type name="abc"/'{print$3} | sed 's/this is ABC/this is ABC EDITED/i') 内容=(cat abc.xml | awk -f'[{}]''/ Type name =“ abc” /'{print $ 3} | sed's /这是ABC /这是ABC EDITED / i')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.