Extraction of data from a simple XML file Extraction of data from a simple XML file bash bash

Extraction of data from a simple XML file


Do you really have to use only those tools? They're not designed for XML processing, and although it's possible to get something that works OK most of the time, it will fail on edge cases, like encoding, line breaks, etc.

I recommend xml_grep:

xml_grep 'job' jobs.xml --text_only

Which gives the output:

programming

On ubuntu/debian, xml_grep is in the xml-twig-tools package.


 grep '<job' file_name | cut -f2 -d">"|cut -f1 -d"<"


Using xmlstarlet:

echo '<job xmlns="http://www.sample.com/">programming</job>' | \   xmlstarlet sel -N var="http://www.sample.com/" -t -m "//var:job" -v '.'