xgrep(1)
π xgrep(1) β General Commands Manual, but make it a vibe π
okay bestie, gather round, because today we're talking about xgrep β a whole General Commands Manual entry that's about to become your new hyperfixation. she searches the content of XML files and she does it flawlessly. no cap. π¦
β¨ NAME β¨
xgrep β search content of an XML file π
π SYNOPSIS π
xgrep [-h] [-v] [-t] [-p] [-n nsdef [-n nsdef]...] [-x xpath] [-s string
[-s string]...] [-c catalog-file] [infile [infile]...]
like, look at her. so many little flags. she's that girl. π
πΈ DESCRIPTION πΈ
so xgrep is literally built to search content inside XML files. iconic behavior.
you tell her what to look for in one of two ways:
- an XPath spec, via the
-xflag π§ - or a custom syntax that includes extended regular expressions, via the
-sflag π§΅
you can also throw multiple input files at her β and if you don't give her any at all? she just reads from stdin, like the low-maintenance queen she is. π«Ά
π OPTIONS π
xgrep accepts the following options, and yes, we're going through every single one because they all matter:
-xxpath β an XPath specification of the elements of interest. that's it, that's the flag. π―-sstring β a custom string format specifying the elements of interest. the format isbase-element:element/regex/,element/regex/,...wherebase-elementis the name of the elements within which a match should be attempted, and the match succeeds if, for eachelement/regex/pair, the content of an element of that name is matched by the corresponding regex. and bestie, if you pass multiple-sflags, a match by any one of them gets returned. obsessed. π₯-nnsdef β define a namespace prefix using the formprefix=namespace. π·οΈ-ccatalog-file β use the specified catalog file instead of the default. π-pβ regular expressions use Perl syntax as implemented in the PCRE library. (heads up: this option is only available whenxgrephas been linked with the PCRE library.) π-tβ text output mode, for generating output formatted for subsequent processing by standard command-line text tools (grep,sed, etc.). linefeeds are converted to spaces within each matching node set, and each node set is separated by a newline. very "plays well with others" of her. β¨-hβ display usage information. π-vβ display version information. π
π EXAMPLES π
okay so picture an XML format for personnel information, where 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, you do:
xgrep -s 'person:name/Smith/,hiredate/2000/' a.xml b.xml
see? she ate. π
now, using XPath to locate elements with a namespace requires use of the -n flag to define a namespace prefix for use in the XPath. so for example, to search for "name" elements within a GPX document, you do:
xgrep -n gpx="http://www.topografix.com/GPX/1/1" \
-x '//gpx:name' data.gpx
namespace? handled. π
π¦ SEE ALSO π¦
regex(7), pcre(3), xmllint(1) β go read those too, bestie, they're part of the friend group. π«Ά
π AUTHOR π
Brendt Wohlberg <software@wohlberg.net> β the mastermind, the moment, the main character. π
and that's the whole page, no skips, no summarising, every flag accounted for. periodt. π
so yeah β that's xgrep(1), straight outta the General Commands Manual, dated 9 August 2013. thank you for coming to my ted talk, ily, go grep something. ππβ¨
π¦ where this page comes from
- fedora 43: xgrep 0.08-25.fc43 Β· GPL-2.0-or-later
- fedora 44: xgrep 0.08-26.fc44 Β· GPL-2.0-or-later
- ubuntu jammy: xgrep 0.08-0ubuntu2
- ubuntu noble: xgrep 0.08-0ubuntu2
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms