User's manual. Section 1.

GR(1): grep files


USAGE

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:

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):

Grep for struct or var declarations in go sources and print them in uppercase:

Grep for struct or var declarations in go sources, filter only those that contain ix, and print them in uppercase,

Grep for struct or var declarations in go sources, filter only those that do not contain ix, and print them in uppercase,

Grep for struct or var declarations in go sources, filter only those that do not contain ix, and print all words in different lines

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


User's manual. Section 1.