STAG-GREP(1)
π 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 ofxml,sxproritext, or the name of a perl module. and guess what,xmlis assumed as default π«-w|writer FORMATβ FORMAT is one ofxml,sxproritext, 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 theSUBargument, iykyk)-q|query TAG1=VAL1-q|query TAG2=VAL2...-q|query TAGN=VALNβ filters based on the fieldTAGπ- other operators can be used too β eg
<,<=, etc - multiple
qarguments can be passed in, stack 'em up - for more complex operations, pass in your own subroutine, see below π
- other operators can be used too β eg
SUBβ a perl subroutine. this subroutine is evaluated every timeNODEis encountered β the stag object forNODEis 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,sxproritext); 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
- fedora 43: perl-Data-Stag 0.14-28.fc43 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms