0

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>

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>

I can edit the 'abc' like this:

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?

Community
  • 1
  • 1
Bishwajyoti Roy
  • 71
  • 1
  • 1
  • 4
  • if you are ok with `sed` : `sed -e 's/this is ABC/& EDITED/' -e 's/this is XYZ/& EDITED/' input.xml` . However, better not to implement this, go with `xmlstarlet` . – P.... Dec 08 '16 at 08:48
  • The String `this is ABC` can be anything. I only know the `name="abc"` . So, can you please tell me how to do this with xmlstarlet? – Bishwajyoti Roy Dec 08 '16 at 08:55
  • I would if I could. Someone else would do. – P.... Dec 08 '16 at 08:57

1 Answers1

0

This could be done using awk

Content = (cat abc.xml | awk -f '[{}]' '/Type name="abc"/'{print$3} | sed 's/this is ABC/this is ABC EDITED/i')