I am trying to edit the XML file using sed. Here is the file content which I am trying to edit.
<configuration key="student1">
<list>
<value>abc</value>
<value>def</value>
</list>
</configuration>
I want to add the following value to the existing node by comparing the key value.
<configuration key="student1">
<list>
<value>abc</value>
<value>NEWVALUE</value>
<value>def</value>
</list>
</configuration>
How can I achieve it using the sed command? After going to lot of posts, xmlstarlet is the best one to edit the xml files. but I am not able to install due to permission issue. Can someone help me for the solution?
Update:
What I have tried is :
sed -i "s/\<\list\>/ \<value\> NEWVALUE\<\/VALUE\>/" xmlfile
This is not working as expected, its replacing the list tag with the NEWVALUE. But I need to compare the key value, then traverse through the lists, then add the new value.
` tag.. and `\<` and `\>` having special meaning of matching word boundaries in GNU sed... what is the key value you want to compare? `student1` or `abc `? in any case, using `sed` here is really not the best idea
– Sundeep Jul 06 '17 at 06:56