GRAM_GREP(1)

πŸ“¦
version 0.10.3 Β· 3 versions
, in epel 10, fedora 43, fedora 44

πŸ’– gram_grep(1) β€” the search bestie πŸ’–

User Commands Β· gram_grep

okay so. you know grep? the icon, the legend, the girl who has been carrying Unix on her back since forever? this is her cooler younger sister. gram_grep πŸ’… she searches for PATTERNs in each FILE or on standard input, and she also has a whole grammar-matching side hustle that regular grep could never. no cap.


✨ NAME ✨

gram_grep β€” Search for PATTERNs in each FILE or standard input πŸ¦‹


✨ SYNOPSIS ✨

gram_grep ([OPTION]... PATTERN)+ [FILE]...

✨ DESCRIPTION ✨

bestie, here's the vibe: you go hunting for PATTERNs inside every FILE you name, or on standard input if you don't name any. πŸŽ€

PATTERN is, by default, a basic regular expression (BRE). and okay, slight plot twist β€” that default only applies to the first PATTERN, which is there for grep(1) compatibility. yes, literally only the first one. it's giving "we keep the old friend around for the lore" 😭


✨ OPTIONS ✨

πŸŽ€ PATTERN SELECTION AND INTERPRETATION

how do you want to read your patterns, queen? pick a lane:

  • -E, --extended-regexp β€” PATTERNs are extended regular expressions ✨
  • -F, --fixed-strings β€” PATTERN is a string (just vibes, no regex)
  • -G, --basic-regexp β€” PATTERNs are basic regular expressions 🫢
  • -P, --perl-regexp β€” PATTERN is a Perl regular expression πŸ‘‘
  • -e, --regexp=PATTERNS β€” use PATTERNs for matching
  • -f, --file=FILE β€” take PATTERNs from FILE
  • -i, --ignore-case β€” ignore case distinctions in patterns and data (so chill of her)
  • --no-ignore-case β€” do not ignore case distinctions (default)
  • -w, --word-regexp β€” match only whole words
  • -x, --line-regexp β€” match only whole lines

🌈 MISCELLANEOUS

the odds and ends shelf, we love her:

  • -s, --no-messages β€” suppress error messages (shhh 🀫)
  • -v, --invert-match β€” select non-matching text
  • -V, --version β€” display version information and exit
  • --help β€” display help text and exit

πŸ’œ OUTPUT CONTROL

this is where she really shows out. all the little knobs for what actually gets printed:

  • -m, --max-count=NUM β€” stop after NUM selected lines
  • -b, --byte-offset β€” print the byte offset with output lines
  • -n, --line-number β€” print line number with output lines
  • --line-buffered β€” flush output on every line
  • -H, --with-filename β€” print file name with output lines
  • -h, --no-filename β€” suppress the file name prefix on output
  • --label=LABEL β€” use LABEL as the standard input file name prefix
  • -o, --only-matching β€” show only nonempty parts of lines that match
  • -q, --quiet, --silent β€” suppress all normal output
  • --binary-files=TYPE β€” assume that binary files are TYPE; TYPE is binary, text, or without-match
  • -a, --text β€” equivalent to --binary-files=text
  • -I β€” equivalent to --binary-files=without-match
  • -d, --directories=ACTION β€” how to handle directories; ACTION is read, recurse, or skip
  • -r, --recursive β€” like --directories=recurse
  • -R, --dereference-recursive β€” likewise, but follow all symlinks πŸŒ€
  • --include=GLOB β€” search only files that match GLOB (a file pattern)
  • --exclude=GLOB β€” skip files that match GLOB
  • --exclude-from=FILE β€” skip files that match any file pattern from FILE
  • --exclude-dir=GLOB β€” skip directories that match GLOB
  • -L, --files-without-match β€” print only names of FILEs with no selected lines
  • -l, --files-with-matches β€” print only names of FILEs with selected lines
  • -c, --count β€” print only a count of selected lines per FILE
  • -T, --initial-tab β€” make tabs line up (if needed)
  • -Z, --null β€” print 0 byte after FILE name

πŸ¦‹ CONTEXT CONTROL

so you can see the ~vibes~ around your match:

  • -B, --before-context=NUM β€” print NUM lines of leading context
  • -A, --after-context=NUM β€” print NUM lines of trailing context
  • -C, --context=NUM β€” print NUM lines of output context
  • -NUM β€” same as --context=NUM
  • --group-separator=SEP β€” print SEP on line between matches with context
  • --no-group-separator β€” do not print separator for matches with context
  • --color[=WHEN], --colour[=WHEN] β€” use markers to highlight the matching strings; WHEN is always, never, or auto 🌈

πŸ‘‘ GRAM_GREP SPECIFIC SWITCHES

okay THIS is the main character section. the stuff plain grep could never:

  • --checkout=CMD β€” checkout command (include $1 for pathname)
  • --config=CONFIG_FILE β€” search using config file
  • --display-whole-match β€” display a multiline match
  • --dump β€” dump DFA regexp
  • --dump-argv β€” dump command line arguments
  • --dump-dot β€” dump DFA regexp in DOT format
  • --exec=CMD β€” Executes the supplied command
  • --extend-search β€” extend the end of the next match to be the current match
  • --flex-regexp β€” PATTERN is a flex style regexp
  • --force-write β€” if a file is read only, force it to be writable
  • --if=CONDITION β€” make search conditional
  • --invert-match-all β€” only match if the search does not match at all
  • -N, --line-number-parens β€” print line number in parenthesis with output lines
  • --perform-output β€” output changes to matching file
  • -p, --print=TEXT β€” print TEXT instead of line of match
  • --print-script=SCRIPT β€” print result of SCRIPT instead of line of match
  • --replace=TEXT β€” replace match with TEXT
  • --replace-script=SCRIPT β€” replace match with result of SCRIPT
  • --return-previous-match β€” return the previous match instead of the current one
  • --shutdown=CMD β€” command to run when exiting
  • --startup=CMD β€” command to run at startup
  • --summary β€” show match count footer
  • --utf8 β€” in the absence of a BOM assume UTF-8
  • -W, --word-list=PATHNAME β€” search for a word from the supplied word list
  • --writable β€” only process files that are writable

✨ FILES ✨

a configuration file can be supplied using --config=CONFIG_FILE. πŸ’–

🧚 CONFIG FILE FORMAT

<grammar directives>
%%
<grammar>
%%
<regexp macros>
%%
<regexes>
%%

🌸 GRAMMAR DIRECTIVES

  • %captures β€” (parenthesis in grammars will be treated as captures)
  • %consume β€” (list tokens that are not to be reported as unused)
  • %option caseless
  • %token
  • %left
  • %right
  • %nonassoc
  • %precedence
  • %start
  • %x

πŸ’« SCRIPTING GRAMMAR

cmd: Name '=' ret_function
   | Name '+=' ret_function
   | 'erase' '(' Index [ ',' Index ] ',' ret_function ')'
   | 'erase' '(' Index '.' first_second ','
             Index '.' first_second ',' ret_function ')'
   | 'insert' '(' Index [ '.' 'second' ] ',' ret_function ')'
   | 'match' '=' Index
   | 'match' '=' 'substr' '(' Index ',' UInt ',' UInt ')'
   | 'match' '+=' Index
   | 'match' '+=' 'substr' '(' Index ',' UInt ',' UInt ')'
   | 'print' '(' ret_function ')';
   | 'replace' '(' Index [ ',' Index ] ',' ret_function ')'
   | 'replace' '(' Index '.' first_second ','
               Index '.' first_second ',' ret_function ')'

   first_second: 'first'
               | 'second';

   ret_function: String
               | Name
               | Index
               | 'capitalise' '(' ret_function ')'
               | 'format' '(' ret_function format_params ')'
               | 'replace_all' '(' ret_function ',' ret_function ','
                               ret_function ')'
               | 'system' '(' ret_function ')'
               | 'tolower' '(' ret_function ')'
               | 'toupper' '(' ret_function ')';

   format_params: %empty
                | format_params ',' ret_function;

πŸŽ€ SCRIPTING TOKENS

Index: $[1-9]\d*

Name:  [A-Z_a-z][-\w]*

String:
       '(''|[^'])*'

UInt:  \d+

🫢 --if SYNTAX

regex_search($n, 'regex'){ || regex_search($n, 'regex')}

tolower($n);

toupper($n);

✨ EXAMPLE ✨

%token RawString String
%%
list: String { match = substr($1, 1, 1); };
list: RawString { match = substr($1, 3, 2); };
list: list String { match += substr($2 1, 1); };
list: list RawString { match += substr($2, 3, 2); };
%%
ws [ \t\r\n]+
%%
\"([^"\\\r\n]|\\.)*\"        String
R\"\((?s:.)*?\)\"            RawString
'([^'\\\r\n]|\\.)*'          skip()
{ws}|"//".*|"/*"(?s:.)*?"*/" skip()
%%

✨ NOTES ✨

ngl bestie, this one's actually useful: you can pipeline searches by using multiple switches. the searches are run in the order they occur on the command line. ⭐

✨ EXAMPLES ✨

gram_grep -i "hello world" menu.h main.c

look at her go. lowercase hello world, two files, chef's kiss πŸ’…


✨ SEE ALSO ✨

grep(1) β€” the OG. respect her name. 🫢


that's the whole page, bestie πŸ’– this one's from the gram_grep manual, User Commands edition, dated April 2026. mwah, go search something iconic βœ¨πŸ‘‘

πŸ“¦ where this page comes from