Hello, I need to find and replace the value of the specific xml element. The conditions are as follows:
- the value of element enabled must be changed from 0 to 1;
- enabled must be the child of an somenode element
My test xml looks like this:
<somenode name="node1">
<some></some>
<enabled>0</enabled>
<some></some>
</somenode>
<someothernode name="node2">
<some></some>
<enabled>0</enabled>
<some></some>
</someothernode>
<somenode name="node3">
<some></some>
<enabled>0</enabled>
<some></some>
</somenode>
I expect that first and third enabled elements would be changed. So far I have managed to write this sed command:
sed -n "1h;1!H;${;g;s|\(<somenode [^>]*>\)\(.*\)\(<enabled>\s*\)0\(\s*</enabled>\)\(.*</somenode>\)|\1\2\3 1 \4\5|g;p;}" test.xml
but it changes only the last one, and I believe it is due to greedy match. Any help would be appreciated.