gram_grep - Man Page
gram_grep – Search for PATTERNs in each FILE or standard input
Synopsis
gram_grep ([OPTION]... PATTERN)+ [FILE]...
Description
Search for PATTERNs in each FILE or standard input. PATTERN is, by default, a basic regular expression (BRE). This is only true for the first PATTERN (for grep(1) compatibility).
Options
Pattern Selection and Interpretation
- -E, --extended-regexp
PATTERNs are extended regular expressions
- -F, --fixed-strings
PATTERN is a string
- -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
- --no-ignore-case
do not ignore case distinctions (default)
- -w, --word-regexp
match only whole words
- -x, --line-regexp
match only whole lines
Miscellaneous
- -s, --no-messages
suppress error messages
- -v, --invert-match
select non-matching text
- -V, --version
display version information and exit
- --help
display help text and exit
Output Control
- -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
- -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
- --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
- --replace=TEXT
replace match with TEXT
- --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
Grammar Scripting
- Note that all strings can contain $n indexes
Functions Returning Strings
- format('text', ...);
(use {} for format specifiers)
replace_all('text', 'regexp', 'text');
system('text');
General Functions
erase($n);
erase($from, $to);
erase($from.second, $to.first);
insert($n, 'text');
insert($n.second, 'text');
match = $n;
match += $n;
match = substr($n, <omit from left>, <omit from right>);
match += substr($n, <omit from left>, <omit from right>);
print('text');
replace($n, 'text');
replace($from, $to, 'text');
replace($from.second, $to.first, 'text');
replace_all($n, 'regexp', 'text');
--if SYNTAX
regex_search($n, 'regex'){ || regex_search($n, 'regex')}
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
Note that 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