grep, egrep, fgrep \- search a file for a pattern
Normally, each line found
is copied to the standard output.
patterns are limited regular expressions in the style of
it uses a compact nondeterministic algorithm.
patterns are full regular expressions;
it uses a fast deterministic algorithm that
sometimes needs exponential space.
patterns are fixed strings; it is fast and compact.
The following options are recognized.
All lines but those matching
(Exact) only lines matched in their entirety are printed
Only a count of matching lines is printed.
The names of files with matching lines are listed (once)
its relative line number in the file.
Each line is preceded by the block number
This is sometimes useful in locating
disk block numbers by context.
The case of letters is ignored in making comparisons.
(E.g. upper and lower case are considered identical.)
(\fIgrep\fR\| and \fIfgrep\fR only)
Nothing is printed (except error messages).
This is useful for checking the error status.
The expression is searched for as a word
(as if surrounded by `\e<' and `\e>', see
In all cases the file name is shown if there is more than one input file.
Care should be taken when
$ * [ ^ | ( ) and \\ in the
also meaningful to the Shell.
It is safest to enclose the
argument in single quotes \' \'.
searches for lines that contain one of the (newline-separated)
accepts extended regular expressions.
In the following description `character' excludes
A \e followed by a single character
The character ^ ($) matches the beginning (end) of
A single character not otherwise endowed with special
meaning matches that character.
A string enclosed in brackets [\|]
matches any single character from the string.
Ranges of ASCII character codes may be abbreviated
may occur only as the first character of the string.
A literal \- must be placed where it can't be
mistaken as a range indicator.
A regular expression followed by * (+, ?) matches a sequence
of 0 or more (1 or more, 0 or 1)
matches of the regular expression.
Two regular expressions concatenated
match a match of the first followed by a match of
Two regular expressions separated by | or newline
match either a match for the first or a match for the
A regular expression enclosed in parentheses
matches a match for the regular expression.
The order of precedence of operators
at the same parenthesis level
*+? then concatenation then | and newline.
Exit status is 0 if any matches are found,
1 if none, 2 for syntax errors or inaccessible files.
Ideally there should be only one
but we don't know a single algorithm that spans a wide enough
range of space-time tradeoffs.
are limited to 256 characters;
longer lines are truncated.