I use with success xmlstarlet in order to replace values from an XML node.
xmlstarlet ed -u //author[text()='Gambardella, Matthew'] -v 'Gambardella' bookstore.xml
<catalog>
<book id="bk101">
<author>Gambardella, Matthew</author>
<title>XML Developer's Guide</title>
<genre>Computer</genre>
<price>44.95</price>
<publish_date>2000-10-01</publish_date>
<description>An in-depth look at creating applications
with XML.</description>
</book>
I have not found a way, to do this in batch mode, say I wanted to replace many author values, found in fileA.txt
:
valueoriginal1
valueoriginal2
valueoriginal3
...
with the values of fileB.txt
:
valuereplacement1
valuereplacement2
valuereplacement3
...
and also, have in another file, a log file, of how many occurrences were changed, what was not changed, and in which particular book id each replacement was made... Perhaps I should use another tool, like sed or awk for this?