.TH egrep "" "" Command
.PC "Extended pattern search"
\fBegrep [\-Abcefhily] [\fIpattern\^\fB] [\fIfile .\^.\^.\^\fB]\fR
.PP
.HS
.SH Options:
.IC \fB\-A\fR
Build \fIerror list\fR for interactive
editing using \*(ME, like \fB\-A\fR
option to the \fBcc\fR command
.IC \fB\-b\fR
Each output line has block number of match
.IC \fB\-c\fR
Print only a count of the matching lines
.IC \fB\-e\fR
Next argument is \fIpattern\fR
.IC \fB\-f\fR
Next argument is file with one pattern per line
.IC \fB\-h\fR
Suppress printing of file names on matched lines
.IC \fB\-i\fR
Ignore case when matching alphabetic characters 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 the sense of match
.IC \fB\-y\fR
Lower-case letters in \fIpattern\fR match upper- and lower-case
.Pp
The \fIpattern\fR is a pattern roughly like that found in \fBed\fR.
If no \fIfile\fR is specified, stdin is read.
\fBegrep\fR is like \fBgrep \-a\fR, but is an order of magnitude faster.
.HE
.B egrep
is an extended and faster version of
.BR grep .
It searches each
.I file
for occurrences of
.I pattern
(also called a regular expression).
If no
.I file
is specified,
it searches the standard input.
Normally,
it prints each line matching the
.IR pattern .
.SH Wildcards
The simplest
.I patterns
accepted by
.B egrep
are ordinary alphanumeric strings.
Like \fBed\fR,
\fBegrep\fR can also process \fIpatterns\fR
that include the following wildcard characters:
.IP \fB\^^\^\fR 0.4i
Match beginning of line, unless it appears immediately after \*(Ql[\*(Qr
(see below).
.IP \fB$\fR
Match end of line.
.IP \fB*\fR
Match zero or more repetitions of preceding character.
.IP \fB\&.\fR
Match any character except newline.
.IP \fB[\fIchars\^\fB]\fR
Match any one of the enclosed
.IR chars .
Ranges
of letters or digits may be indicated using \*(Ql\-\*(Qr.
.IP \fB[\^^\^\fIchars\^\fB]\fR
Match any character
.I except
one of the enclosed
.IR chars .
Ranges
of letters or digits may be indicated using \*(Ql\-\*(Qr.
.IP \fB\e\fIc\fR
Disregard special meaning of character
.IR c .
.SH Metacharacters
In addition,
.B egrep
accepts
the following additional metacharacters:
.IP \fB|\fR 0.4i
Match the preceding pattern
.I or
the following pattern.
For example, the pattern
.B cat\^|\^dog
matches either
.B cat
or
.BR dog .
A newline within the
.I pattern
has the same meaning as \*(Ql|\*(Qr.
.IP \fB+\fR
Match one or more occurrences
of the immediately preceding pattern element;
it works like \*(Ql*\*(Qr, except it matches at least one occurrence
instead of zero or more occurrences.
.IP \fB?\fR
Match zero or one occurrence of the
preceding element of the pattern.
.IP \fB(\^.\^.\^.\^)\fR
Parentheses may be used to group patterns.
For example,
.B (Ivan)+
matches a sequence of one or more occurrences
of the four letters \*(QlI\*(Qr \*(Qlv\*(Qr \*(Qla\*(Qr or \*(Qln\*(Qr.
.PP
Because the metacharacters
\*(Ql*\*(Qr, \*(Ql?\*(Qr,
\*(Ql$\*(Qr, \*(Ql(\*(Qr, \*(Ql)\*(Qr, \*(Ql[\*(Qr, \*(Ql]\*(Qr,
and \*(Ql|\*(Qr
are also special to
the shell,
patterns that contain those literal characters must be quoted by enclosing
.I pattern
within apostrophes.
.SH Options
The following lists the available options:
.IP \fB\-A\fR 0.3i
Write all lines in which
.I expression
is found into a temporary file.
Then, call \*(CO with its error option to process the source file,
with the contents of the temporary file serving as an ``error'' list.
This option resembles the \fB\-A\fR option to the \fBcc\fR command, and
lets you build a \*(CO script to make systematic changes to the
source file.
To exit \*(CO and prevent
.B egrep
from searching further, \fB<ctrl-U> <ctrl-X> <ctrl-C>\fR.
.sp \n(pDu
Unlike
.BR cgrep ,
.B egrep
only matches patterns that are on a single line.
Some systems have a context
.B grep (also named
.BR cgrep )
that works like
.B egrep
but displays lines found in context.
The \*(CO
.B "egrep \-A"
not only displays lines in context, via \*(CO, it lets you edit them.
.IP \fB\-b\fR
With each output line, print the block number in which the line started
(used to search file systems).
.IP \fB\-c\fR
Print how many lines match, rather than the lines themselves.
.IP \fB\-e\fR
The next argument is
.I pattern
(useful if the pattern starts with \*(Ql\-\*(Qr).
.IP \fB\-f\fR
The next argument is a file that contains 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 matches alphabetic letter in \fIpattern\fR.
.B egrep
takes case into account, even with this option, when you prefix a letter in
.I pattern
with `\e'.
.IP \fB\-l\fR
Print the name of each file that contains the string,
rather than the lines themselves.
This is useful when you are constructing a batch file.
.IP \fB\-n\fR
When a line is printed, also print its number within the file.
.IP \fB\-s\fR
Suppress all output, just return exit status.
.IP \fB\-v\fR
Print a line only if the pattern is
.I not
found in the line.
.IP \fB\-y\fR
Lower-case letters in the pattern match only
upper-case letters on the input lines.
A letter escaped with \*(Ql\e\*(Qr
in the pattern must be matched in exactly that case.
.SH Limits
The \*(CO implementation of
.B egrep
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 "awk," awk
.Xr "cgrep," cgrep
.Xr "commands," commands
.Xr "ed," ed
.Xr "expr," expr
.Xr "grep," grep
.Xr "lex," lex
.Xr "sed" sed
.SH Diagnostics
.B egrep
returns an
exit status of zero for success, one for no matches, and two for error.
.SH Notes
For matching patterns in C programs, the command
.B cgrep
is preferred, because it is optimized to recognize C-style expressions.
.PP
Besides the difference in the range of patterns allowed,
.B egrep
uses a deterministic finite automaton (DFA) for the search.
It builds the DFA dynamically, so it
begins doing useful work immediately.
This means that
.B egrep
is
is much faster than
.BR grep ,
often by more than an order of magnitude, and is
considerably faster than earlier pattern-searching commands,
on almost any length of file.
