blob: 2389062187f3daf3bc415984ddcc1d4df9817cd4 [file] [log] [blame]
grep, g \- search a file for a pattern
.B grep
.I option ...
.I pattern
.I file ...
.B g
.I option ...
.I pattern
.I file ...
.I Grep\^
searches the input
.I files\^
(standard input default)
for lines that match the
.IR pattern ,
a regular expression as defined in
.IR regexp (7)
with the addition of a newline character as an alternative
(substitute for
.BR | )
with lowest precedence.
Normally, each line matching the pattern is `selected',
and each selected line is copied to the standard output.
The options are
.B -c
Print only a count of matching lines.
.PD 0
.B -h
Do not print file name tags (headers) with output lines.
.B -e
The following argument is taken as a
.IR pattern .
This option makes it easy to specify patterns that
might confuse argument parsing, such as
.BR -n .
.B -i
Ignore alphabetic case distinctions. The implementation
folds into lower case all letters in the pattern and input before
interpretation. Matched lines are printed in their original form.
.B -l
(ell) Print the names of files with selected lines; don't print the lines.
.B -L
Print the names of files with no selected lines;
the converse of
.BR -l .
.B -n
Mark each printed line with its line number counted in its file.
.B -s
Produce no output, but return status.
.B -v
Reverse: print lines that do not match the pattern.
.B -f
The pattern argument is the name of a file containing regular
expressions one per line.
.B -b
Don't buffer the output: write each output line as soon as it is discovered.
Output lines are tagged by file name when there is more than one
input file.
(To force this tagging, include
.B /dev/null
as a file name argument.)
Care should be taken when
using the shell metacharacters
.B $*[^|()=\e
and newline
.IR pattern ;
it is safest to enclose the
entire expression
in single quotes
.BR \&\|' \|.\|.\|.\| ' .
An expression starting with '*'
will treat the rest of the expression
as literal characters.
.I G
invokes grep with
.B -n
and forces tagging of output lines by file name.
If no files are listed, it searches all files matching
*.C *.b *.c *.h *.m *.cc *.java *.cgi *.pl *.py *.tex *.ms
.B \*9/src/cmd/grep
.B \*9/bin/g
.IR ed (1),
.IR awk (1),
.IR sed (1),
.IR sam (1),
.IR regexp (7)
Exit status is null if any lines are selected,
or non-null when no lines are selected or an error occurs.