Search code examples
xmlbashsearchreplacequotes

Remove or replace double quotes from values of XML (specific search and replace)


I have the following XML:

<smtng attr="bla"><desc>bla 12" bla</desc></smtng>

And I would like to use some command (preferably executable from bash) to replace the " after 12 with &quot;, but leave it as it is for the attr="bla" part...

Any ideas?


Solution

  • This may work, but you should really use the proper tools.

    sed 's|</\?desc>|\n&|g; s/\(<desc>[^"]*\)"\([^\n]*\n\)/\1\&quot;\2/g;s/\n//g' inputfile