user1654528
user1654528

Reputation: 405

Using AWK what's the best way to change an XML property

Using AWK how can I change the property enabled="true" to enabled="false" . I need to do this for all occurrences in the ResultCollector only.

Before:

 <asdjasl enabled="true">

    <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">
    <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="true">

 <asdjasl enabled="true">

After:

 <asdjasl enabled="true">

    <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false">
    <ResultCollector guiclass="ViewResultsFullVisualizer" testclass="ResultCollector" testname="View Results Tree" enabled="false">

 <asdjasl enabled="true">

Upvotes: 0

Views: 91

Answers (1)

glenn jackman
glenn jackman

Reputation: 247012

The best way to change an XML property is with an XML processing tool, not a text processing tool. I'd use

xmlstarlet ed --inplace --update '//ResultCollector/@enabled' --value 'false' file.xml

Upvotes: 2

Related Questions