I need a bash script for updating part of XML element value according to some other dynamic property.
For example, the XML file:
<?xml version="1.0" encoding="ISO-8859-1"?>
<Configure class="org.eclipse.something">
<Set name="foo">foo-val</Set>
<Set name="bar">bar-val</Set>
<Set name="my-elm">/dont/matter/THIS_ONE_NEED_TO_BE_UPDATED</Set>
</Configure>
Tried to use xmlstarlet with regexing, but it's not providing the result I want. I'm working on OSX 10.12.
Using
xmlstarletwith belowxpathexpression worked fine for me. The below expression does in-pace substitution (-Lflag) of theXMLfileDrop the
-Lflag to check if the replacement is occurring properly, and once successful add the same.Checked on
xmlstarlet (1.6.1)onOS XThough it is strictly
NOTadvised to usesedforxmlupdates, this below logic will work for you,add the
-i.bakfor in-place substitution of the file.