BSD 4_4_Lite2 development
[unix-history] / usr / share / man / cat1 / fgrep.0
GREP(1) BSD Reference Manual GREP(1)
N\bNA\bAM\bME\bE
g\bgr\bre\bep\bp - file pattern searcher
S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
g\bgr\bre\bep\bp [-\b-b\bbc\bch\bhi\bil\bln\bno\bos\bsv\bvw\bw] [-\b-e\be _\bp_\ba_\bt_\bt_\be_\br_\bn] [_\bf_\bi_\bl_\be _\b._\b._\b.]
e\beg\bgr\bre\bep\bp [-\b-b\bbc\bch\bhi\bil\bln\bno\bos\bsv\bv] [-\b-e\be _\bp_\ba_\bt_\bt_\be_\br_\bn] [-\b-f\bf _\bp_\ba_\bt_\bt_\be_\br_\bn_\b__\bf_\bi_\bl_\be] [_\bf_\bi_\bl_\be _\b._\b._\b.]
f\bfg\bgr\bre\bep\bp [-\b-b\bbc\bch\bhi\bil\bln\bno\bos\bsv\bvx\bx] [-\b-e\be _\bp_\ba_\bt_\bt_\be_\br_\bn] [-\b-f\bf _\bp_\ba_\bt_\bt_\be_\br_\bn_\b__\bf_\bi_\bl_\be] [_\bf_\bi_\bl_\be _\b._\b._\b.]
D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
The g\bgr\bre\bep\bp utilities search the given input files selecting lines which
match one or more patterns; the type of patterns is controlled by the op-
tions specified. By default, a pattern matches an input line if any reg-
ular expression (RE) in the pattern matches the input line without its
trailing <new-line>. A null RE matches every line. Each input line that
matches at least one of the patterns is written to the standard output.
For simple patterns or ex(1) or ed(1) style regular expressions, the g\bgr\bre\bep\bp
utility is used. The e\beg\bgr\bre\bep\bp utility can handle extended regular expres-
sions and embedded <newline>s in patterns. The f\bfg\bgr\bre\bep\bp utility is quick
but can handle only fixed strings. A fixed string is a string of charac-
ters, each character is matched only by itself. The pattern value can
consist of multiple lines with embedded <newline>s. In this case, the
<newline>s act as alternation characters, allowing any of the pattern
lines to match a portion of the input.
The following options are available:
-\b-b\bb The block number on the disk in which a matched pattern is locat-
ed is displayed in front of the respective matched line.
-\b-c\bc Only a count of selected lines is written to standard output.
-\b-e\be _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn
Specify a pattern used during the search of the input. Multiple
-\b-e\be options can be used to specify multiple patterns; an input
line is selected if it matches any of the specified patterns.
-\b-f\bf _\bp_\ba_\bt_\bt_\be_\br_\bn_\b__\bf_\bi_\bl_\be
The pattern is read from the file named by the pathname pat-
tern_file. Trailing newlines in the pattern_file are ignored.
(E\bEg\bgr\bre\bep\bp and f\bfg\bgr\bre\bep\bp only).
-\b-h\bh Never print filename headers with output lines.
-\b-i\bi The case of letters is ignored in making comparisons - that is,
upper and lower case are considered identical.
-\b-l\bl Only the names of files containing selected lines are written to
standard output. Pathnames are listed once per file searched.
If the standard input is searched, the pathname `-\b-' is written.
-\b-n\bn Each output line is preceded by its relative line number in the
file; each file starting at line 1. The line number counter is
reset for each file processed. This option is ignored if -\b-c\bc, -\b-l\bl,
or -\b-s\bs is specified.
-\b-o\bo Always print filename headers with output lines.
-\b-s\bs Silent mode. Nothing is printed (except error messages). This
is useful for checking the error status.
-\b-v\bv Selected lines are those _\bn_\bo_\bt matching the specified patterns.
-\b-x\bx Only input lines selected against an entire fixed string or regu-
lar expression are considered to be matching lines. (F\bFg\bgr\bre\bep\bp on-
ly).
-\b-w\bw The expression is searched for as a word (as if surrounded by
`\<' and `\>', see ex(1).) (G\bGr\bre\bep\bp only)
If no file arguments are specified, the standard input is used.
The g\bgr\bre\bep\bp utility exits with one of the following values:
0 One or more lines were selected.
1 No lines were selected.
>1 An error occurred.
E\bEX\bXT\bTE\bEN\bND\bDE\bED\bD R\bRE\bEG\bGU\bUL\bLA\bAR\bR E\bEX\bXP\bPR\bRE\bES\bSS\bSI\bIO\bON\bNS\bS
The following characters are interpreted by e\beg\bgr\bre\bep\bp:
$\b$ Align the match from the end of the line.
^\b^ Align the match from the beginning of the line.
|\b| Add another pattern (see example below).
?\b? Match 1 or less sequential repetitions of the pattern.
+\b+ Match 1 or more sequential repetitions of the pattern.
*\b* Match 0 or more sequential repetitions of the pattern.
[\b[]\b] Match any single character or range of characters enclosed in the
brackets.
\\b\ Escape special characters which have meaning to e\beg\bgr\bre\bep\bp, the set of
{$,.,^,[,],|,?,+,*,(,)}.
E\bEX\bXA\bAM\bMP\bPL\bLE\bES\bS
To find all occurrences of the word patricia in a file:
grep patricia myfile
To find all occurrences of the pattern `.Pp' at the beginning of a line:
grep '^\.Pp'
The apostrophes assure the entire expression is evaluated by g\bgr\bre\bep\bp instead
of by the users shell. The carat or hat `^' means _\bf_\br_\bo_\bm _\bt_\bh_\be _\bb_\be_\bg_\bi_\bn_\bn_\bi_\bn_\bg _\bo_\bf
_\ba _\bl_\bi_\bn_\be, and the `\' escapes the `.' which would otherwise match any char-
acter.
A simple example of an extended regular expression:
egrep '19|20|25' calendar
Peruses the file calendar looking for either 19, 20 or 25.
S\bSE\bEE\bE A\bAL\bLS\bSO\bO
ed(1), ex(1), sed(1)
H\bHI\bIS\bST\bTO\bOR\bRY\bY
The g\bgr\bre\bep\bp command appeared in Version 6 AT&T UNIX.
B\bBU\bUG\bGS\bS
Lines are limited to 256 characters; longer lines are truncated.
4.4BSD April 18, 1994 2