xgrep(1) | General Commands Manual | xgrep(1) |
xgrep ‐ search content of an XML file
xgrep [-h] [-v] [-t] [-p] [-n nsdef [-n nsdef]...] [-x xpath] [-s string [-s string]...] [-c catalog-file] [infile [infile]...]
xgrep provides facilities for searching content in XML files. The search is specified either as an XPath via the -x flag, or a custom syntax including extended regular expressions via the -s flag. Multiple input files may be specified; if none are provided, input is read from stdin.
xgrep accepts the following options:
Consider an XML format, for personnel information, in which each person element has descendant elements called name and hiredate. To find all person elements with "Smith" in the content of the name element and "2000" in the content of the hiredate element, do:
xgrep -s 'person:name/Smith/,hiredate/2000/' a.xml b.xml
Using XPath to locate elements with a namespace requires use of the -n flag to define a namespace prefix for use in the XPath. For example to search for "name" elements within a GPX document, do:
xgrep -n gpx="http://www.topografix.com/GPX/1/1" \
-x '//gpx:name' data.gpx
regex(7), pcre(3), xmllint(1)
Brendt Wohlberg <software@wohlberg.net>
9 August 2013 |