GR(1): grep files
__________________________________________________
USAGE
usage: gr [-Daeflmsuvx] rexp [rexp]
-D: debug
-a: print just addresses
-e: extend regexps to match all the text
-f: print addresses for matches in full files (like sam)
-l: print just the names of matching files
-m: print just matching text
-s: just status
-u: use unix out
-v: invert match
-x: print selections for further editing commands
gg is gr -xef
gv is gr -xvef
gx is gr -xf
DESCRIPTION
Gr greps zx files for the expression given. If two expressions
are given, they match the text starting at the match for the
first expression and ending at the text matching the second one.
This is similar to an address in Sam and Acme editors.
By default it operates on a line by line basis, but most
interesting usages rely on flag -f that operates on full files.
Flag -x deserves a note. It makes the command pass to the output
unmatched text as ignored output, which means that such data is
ignored by default by most other commands, but can be retrieved
later, in-place, by tools like pf(1). Also, it makes gr report as
zx.Addr data types the addresses for matches into the output, and
pf knows how to print those.
EXAMPLES
Grep for func at the start of line in all files in the subtree
rooted at the current directory:
; lf -g ,- | gr -u '^func'
Grep to select lines with func at the start of line, translate
those lines to uppercase, and print resulting files (both
selected and unselected lines):
lf -g ,- | gr -xf '^func.*\n' | trex -c | pf -i
Grep for struct or var declarations in go sources and print them
in uppercase:
lf -g ,~*.go | gr -xf '^(struct|var)' '^(}|\))\n' | trex -c
| pf
Grep for struct or var declarations in go sources, filter only
those that contain ix, and print them in uppercase,
lf -g ,~*.go | gr -xf '^(struct|var)' '^(}|\))\n' |
gr -xfe ix | trex -c | pf
Grep for struct or var declarations in go sources, filter only
those that do not contain ix, and print them in uppercase,
lf -g ,~*.go | gr -xf '^(struct|var)' '^(}|\))\n' |
gr -xfev ix | trex -c | pf
Grep for struct or var declarations in go sources, filter only
those that do not contain ix, and print all words in different
lines
lf -g ,~*.go | gr -xf '^(struct|var)' '^(}|\))\n' |
gr -xfve ix | gr -xf '[a-zA-Z]+' | pf -s
Popular aliases are gg for gr -xef, similar to the g command in
Sam. gv for gr -xvef, similar to the v command in Sam. gx for gr
-xf, similar to the x command in Sam.
SOURCE
+o /zx/sys/src/clive/cmd/gr
__________________________________________________
User's manual. Section 1. Copyright © LSUB 2014-2016