extract xml from the command line

I just discovered this morning this cool utility in my /bin directory : xmllint

You can use it to extract values from your xml files within your shell scripts

$ cat foo.xml
  <emp no="1">
  <emp no="2">
$ echo 'cat //emplist/emp[@no="1"]/ename/text()'|
  xmllint --shell foo.xml |
  sed -n 3p

I like this !

Published by

Laurent Schneider

Oracle Certified Master

3 thoughts on “extract xml from the command line”

  1. sed -n 3p
    did not work for me
    sed -n 2p
    did work!

    …or use sed to delete the lines with the “/ > ” prompt?

    sed ‘/^\/ >/ d’

Leave a Reply