I've got to replace some attribute content in an XML tag, depending on a parameter $1.We've got in input, for example:<ThreadGroup guiclass=ThreadGroupGui testclass=ThreadGroup testname=OO CSS DPM PRI enabled=true><ThreadGroup guiclass=ThreadGroupGui testclass=ThreadGroup testname=AA CSS DPM PRI enabled=true>If the testname attribute does not contain $1, then replace the enabled value with false; otherwise (testname does contain $1), replace the enabled value with true.NOTE: it's possible to encounter other attributes, more than in this example.I thought about sed but maybe other tools can do it better?
Replacement of XML based on attribute content using sed
sed;replace;xml
If I understood the logic correctly, this sed command searches for the given $1 parameter inside of the testname value; if it's present, then search and replace the enabled value from false to true. If it's not (!) present, then replace the enabled value from true to false.sed '/ testname=[^]*'$1'[^]*/ s/ enabled=false/ enabled=true/;     / testname=[^]*'$1'[^]*/!s/ enabled=true/ enabled=false/' input > outputI tried to help the regex matching by giving leading spaces before the attribute names (both testname and enabled), and by using the [^] character class.