Search code examples
xmlreplacereplaceall

How to find and replace on patterns like ‘something=“string”’ on Linux?


I have an XML file in which there are tags like below.

<project name=“something” revision=“abc” />
<project name=“something2” revision=“xyz” />
...

How can I replace ‘revision=“string here”’ with my own strings on Linux (Ubuntu)?


Solution

  • The right tool for this job is XSLT. There's a bit of a learning curve, but it's very powerful and you should really be using XML-aware tools to process XML files (if you use non-XML-aware tools like sed, there's a great risk of producing invalid XML).