BSD 4_4 development
[unix-history] / usr / share / man / cat1 / egrep.0
CommitLineData
98473598
C
1GREP(1) BSD Reference Manual GREP(1)
2
3N\bNA\bAM\bME\bE
4 g\bgr\bre\bep\bp - file pattern searcher
5
6S\bSY\bYN\bNO\bOP\bPS\bSI\bIS\bS
7 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.]
8 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.]
9 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.]
10
11D\bDE\bES\bSC\bCR\bRI\bIP\bPT\bTI\bIO\bON\bN
12 The g\bgr\bre\bep\bp utilities search the given input files selecting lines which
13 match one or more patterns; the type of patterns is controlled by the op-
14 tions specified. By default, a pattern matches an input line if any reg-
15 ular expression (RE) in the pattern matches the input line without its
16 trailing <new-line>. A null RE matches every line. Each input line that
17 matches at least one of the patterns is written to the standard output.
18
19 For simple patterns or ex(1) or ed(1) style regular expressions, the g\bgr\bre\bep\bp
20 utility is used. The e\beg\bgr\bre\bep\bp utility can handle extended regular expres-
21 sions and embedded <newline>s in pattern f\bfg\bgr\bre\bep\bp is quick but is designed
22 to handle fixed strings. A fixed string is a string of characters, each
23 character is matched only by itself. The pattern value can consist of
24 multiple lines with embedded <newline>s. In this case, the <newline>s
25 act as alternation characters, allowing any of the pattern lines to match
26 a portion of the input.
27
28 The following options are available:
29
30 -\b-b\bb The block number on the disk in which a matched pattern is locat-
31 ed is displayed in front of the respective matched line.
32
33 -\b-c\bc Only a count of selected lines is written to standard output.
34
35 -\b-e\be _\be_\bx_\bp_\br_\be_\bs_\bs_\bi_\bo_\bn
36 Specify a pattern used during the search of the input. Multiple
37 -\b-e\be options can be used to specify multiple patterns; an input
38 line is selected of it matches any of the specified patterns.
39
40 -\b-f\bf _\bp_\ba_\bt_\bt_\be_\br_\bn_\b__\bf_\bi_\bl_\be
41 The pattern is read from the file named by the pathname pat-
42 tern_file. Trailing newlines in the pattern_file are ignored.
43 (E\bEg\bgr\bre\bep\bp and f\bfg\bgr\bre\bep\bp only).
44
45 -\b-h\bh Never print filename headers with output lines.
46
47 -\b-i\bi The case of letters is ignored in making comparisons - that is,
48 upper and lower case are considered identical.
49
50 -\b-l\bl Only the names of files containing selected lines are written to
51 standard output. Pathnames are listed once per file searched.
52 If the standard input is searched, the pathname `-\b-' is written.
53
54 -\b-n\bn Each output line is preceded by its relative line number in the
55 file; each file starting at line 1. The line number counter is
56 reset for each file processed. This option is ignored if -\b-c\bc, -\b-l\bl,
57 or -\b-s\bs is specified.
58
59 -\b-o\bo Always print filename headers with output lines.
60
61 -\b-s\bs Silent mode. Nothing is printed (except error messages). This
62 is useful for checking the error status.
63
64
65
66 -\b-v\bv Selected lines are those _\bn_\bo_\bt matching the specified patterns.
67
68 -\b-x\bx Only input lines selected against an entire fixed string or regu-
69 lar expression are considered to be matching lines. (F\bFg\bgr\bre\bep\bp on-
70 ly).
71
72 -\b-w\bw The expression is searched for as a word (as if surrounded by
73 `\<' and `\>', see ex(1).) (G\bGr\bre\bep\bp only)
74
75 If no file arguments are specified, the standard input is used.
76
77 The g\bgr\bre\bep\bp utility exits with one of the following values:
78
79 0 One or more lines were selected.
80 1 No lines were selected.
81 >1 An error occurred.
82
83E\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
84 The following characters are interpreted by e\beg\bgr\bre\bep\bp:
85
86 $\b$ Align the match from the end of the line.
87 ^\b^ Align the match from the beginning of the line.
88 |\b| Add another pattern (see example below).
89 ?\b? Match 1 or less sequential repetitions of the pattern.
90 +\b+ Match 1 or more sequential repetitions of the pattern.
91 *\b* Match 0 or more sequential repetitions of the pattern.
92 [\b[]\b] Match any single character or range of characters enclosed in the
93 brackets.
94 \\b\ Escape special characters which have meaning to e\beg\bgr\bre\bep\bp, the set of
95 {$,.,^,[,],|,?,+,*,(,)}.
96
97E\bEX\bXA\bAM\bMP\bPL\bLE\bES\bS
98 To find all occurances of the word patricia in a file:
99
100 grep patricia myfile
101
102 To find all occurences of the pattern `.Pp' at the beginning of a line:
103
104 grep '^\.Pp'
105
106 The apostrophys assure the entire expression is evaluated by g\bgr\bre\bep\bp instead
107 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
108 _\ba _\bl_\bi_\bn_\be, and the `\' escapes the `.' which would otherwise match any char-
109 acter.
110
111 A simple example of an extended regular expression:
112
113 egrep '19|20|25' calendar
114
115 Peruses the file calendar looking for either 19, 20 or 25.
116
117S\bSE\bEE\bE A\bAL\bLS\bSO\bO
118 ed(1), ex(1), sed(1)
119
120H\bHI\bIS\bST\bTO\bOR\bRY\bY
121 The g\bgr\bre\bep\bp command appeared in Version 6 AT&T UNIX.
122
123B\bBU\bUG\bGS\bS
124 Lines are limited to 256 characters; longer lines are truncated.
125
1264.4BSD June 6, 1993 2