.TH grep "" "" Command
.PC "Pattern search"
.PP	
.HS
.SH Options:
.IC \fB\-a\fR
Extra metacharacters supported (`(...)', `|', `+', and `?')
.IC \fB\-b\fR
Each output line has block number of match
.IC \fB\-c\fR
Print only count of matching lines
.IC \fB\-e\fR
Next argument is pattern
.IC \fB\-f\fR
Next argument is file containing one pattern per line
.IC \fB\-h\fR
Suppress printing of file names on matched lines
.IC \fB\-i\fR
Ignore case when matching letters in \fIpattern\fR
.IC \fB\-l\fR
Print only names of files containing matches
.IC \fB\-n\fR
Print line number of file with each matched line output
.IC \fB\-s\fR
Suppress output, just return status
.IC \fB\-v\fR
Negate sense of match
.IC \fB\-x\fR
Exact match (don't expand metacharacters)
.IC \fB\-y\fR
Lower-case letters in \fIpattern\fR match only upper-case
.Pp
The \fIpattern\fR is a regular expression roughly like that found in \fBed\fR.
If no \fIfile\fR is specified, stdin is read.
.HE
.B grep
searches each
.I file
for occurrences of the
.I pattern
(sometimes called a regular expression).
If no
.I file
is specified,
.B grep
searches the standard input.
The
.I pattern
is given in the same manner as to
.BR ed .
Normally,
.B grep
prints each line matching the
.I pattern.
.PP
.B grep
recognizes the following command-line options:
.IP \fB\-b\fR 0.4i
With each output line, print the block number in which the line started
(used to search file systems).
.IP \fB\-c\fR
Print the count of matching lines rather than the lines.
.IP \fB\-e\fR
The next argument is
.I pattern
(useful if the pattern starts with `\-').
.IP \fB\-f\fR
The next argument is a file that contain a list of patterns separated by
newlines; there is no
.I pattern
argument.
.IP \fB\-h\fR
When more than one
.I file
is specified, output lines are normally accompanied by the file name;
.B \-h
suppresses this.
.IP \fB\-i\fR
Ignore case when matching letters in \fIpattern\fR.
For example, an `a' in
.I pattern
matches either `a' or `A' in
.IR file ;
likewise, an `A' in
.I pattern
matches either `a' or `A'.
.IP \fB\-l\fR
Print the name of each file containing matching lines rather than the lines.
.IP \fB\-n\fR
The line number in the file accompanies each line printed.
.IP \fB\-s\fR
Suppress all output, just return status.
.IP \fB\-v\fR
Print a line if the pattern is
.I not
found in the line.
.IP \fB\-x\fR
Print the line only if it is exactly the same as the pattern;
treat wildcards in the pattern as plain text.
.IP \fB\-y\fR
Lower-case letters in
.I pattern
match only upper-case letters within the input lines.
.SH Limits
The \*(CO implementation of
.B grep
sets the following limits on input and output:
.DS
.ie t .ta 0.5i 3.0i
.el   .ta 0.5i 4.0i
	Characters per input record	512
	Characters per output record	512
	Characters per field	512
.DE
.SH "See Also"
.Xr "cgrep," cgrep
.Xr "commands," commands
.Xr "ed," ed
.Xr "egrep," egrep
.Xr "zgrep" zgrep
.SH Diagnostics
.B grep
returns an exit status of zero for success, one for no matches, two for error.
.SH Notes
.B cgrep
is a version of
.B grep
that is optimized for handling C-style expressions.
.PP
.B egrep
is an extended and faster version of
.BR grep .
