Linux Commands - xml_grep (parse XML file)

by
Jeremy Canfield |
Updated: November 26 2020
| Linux Commands articles
Let's say example.xml contains the following.
<items>
<id>123</id>
<item>Shoes</item>
<id>456</id>
<item>Boots</item>
</items>
The xml_grep command can be used to parse the XML file. In this example, the item tags are parsed.
xml_grep 'item' example.xml
Which should return the following output.
<?xml version="1.0" ?>
<xml_grep version="0.9" date="Thu Aug 17 20:59:36 2017">
<file filename="example.xml">
<item>Shoes</item>
<item>Boots</item>
</file>
</xml_grep>
--text_only can be used to only display the value in a certain XML tag.
xml_grep 'item' example.xml --text_only
Which should return the following.
Shoes
Boots
Did you find this article helpful?
If so, consider buying me a coffee over at
Comments
September 16 2020 by Ramnath
Thank you