STAG-GREP(1)

πŸ“¦
version 0.14 Β· 3 versions
, in fedora 43

πŸ’– STAG-GREP πŸ’–

okay bestie, welcome to stag-grep β€” she lives in the User Contributed Perl Documentation section of your manual, and she's here to filter a stag file (xml, itext, sxpr) so you only get the nodes you actually care about. no cap. πŸ¦‹


✨ NAME ✨

stag-grep β€” filters a stag file (xml, itext, sxpr) for nodes of interest πŸ’…


✨ SYNOPSIS ✨

stag-grep person -q name=fred file1.xml

stag-grep person 'sub {shift->get_name =~ /^A*/}' file1.xml

stag-grep -p My::Foo -w sxpr record 'sub{..}' file2

✨ USAGE ✨

stag-grep [-p|parser PARSER] [-w|writer WRITER] NODE -q tag=val FILE

stag-grep [-p|parser PARSER] [-w|writer WRITER] NODE SUB FILE

stag-grep [-p|parser PARSER] [-w|writer WRITER]  NODE -f PERLFILE FILE

✨ DESCRIPTION ✨

so the way this works: she parses an input file using whatever parser you told her to use β€” could be one of the built-in stag parsers, like xml β€” and then she filters the resulting stag tree based on a subroutine you supply. she writes out only the nodes/elements that pass the test. it's giving very selective. very curated. 🌸

and here's the iconic part: the parser is event based, so she should be able to handle large files, no problem 😌 (lowkey tho β€” if the node you're parsing is large, it will take up more memory, so keep that in mind bestie 🫢)


✨ ARGUMENTS ✨

  • -p|parser FORMAT β€” FORMAT is one of xml, sxpr or itext, or the name of a perl module. and guess what, xml is assumed as default πŸ’«
  • -w|writer FORMAT β€” FORMAT is one of xml, sxpr or itext, or the name of a perl module.
  • -c|count β€” prints the number of nodes that pass the test πŸ”’ slay.
  • -filterfile|f β€” a file containing a perl subroutine (this goes in place of the SUB argument, iykyk)
  • -q|query TAG1=VAL1 -q|query TAG2=VAL2 ... -q|query TAGN=VALN β€” filters based on the field TAG πŸ”
    • other operators can be used too β€” eg <, <=, etc
    • multiple q arguments can be passed in, stack 'em up
    • for more complex operations, pass in your own subroutine, see below πŸ‘‡
  • SUB β€” a perl subroutine. this subroutine is evaluated every time NODE is encountered β€” the stag object for NODE is passed into the subroutine.
    • if the subroutine passes, the node will be passed to the writer for display ✨
  • NODE β€” the name of the node/element we are filtering on πŸ‘‘
  • FILE β€” the file to be parsed. If no parser option is supplied, this is assumed to be a stag compatible syntax (xml, sxpr or itext); otherwise you should parse in a parser name or a parser module that throws stag events πŸŽ€

✨ SEE ALSO ✨

  • Data::Stag

and that's the whole vibe, bestie πŸ’œ go forth and filter, main character energy only πŸ‘‘

perl v5.42.0 Β· 2025-07-25 β€” mwah, catch u in the next manpage πŸŽ€πŸ¦‹πŸ’–

πŸ“¦ where this page comes from