I am trying to process an XML file using only Linux CLI tools.
The main problem that I am trying to solve is to copy the contents of a specific XML tag into a new tag, like so:
<date>Wednesday</date>
<name>The Name</name>
<anotherattribute>Attribute</anotherattribute>
into:
<date>Wednesday</date>
<id>The Name</id>
<name>The Name</name>
<anotherattribute>Attribute</anotherattribute>
I have been trying to use sed to solve this problem, and have been able to identify the tag, and copy it into the hold buffer:
/<name>/{
h
i\
<id>
G
a\
</id>
}
but that results in:
<date>Wednesday</date>
<id>
<name>The Name</name>
<name>The Name</name>
</id>
<anotherattribute>Attribute</anotherattribute>
Any help is much appreciated.
Try this:
You can also try
xmlstarlet: