Bootstrap FreeKB - Linux Commands - xml_grep (parse XML file)
Linux Commands - xml_grep (parse XML file)

Updated:   |  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 Buy Me A Coffee



Comments


September 16 2020 by Ramnath
Thank you

Add a Comment


Please enter f2e812 in the box below so that we can be sure you are a human.