Commit | Line | Data |
---|---|---|
732dc260 KM |
1 | .\" Copyright (c) 1980 Regents of the University of California. |
2 | .\" All rights reserved. The Berkeley software License Agreement | |
3 | .\" specifies the terms and conditions for redistribution. | |
4 | .\" | |
5 | .\" @(#)grep.1 4.1 (Berkeley) %G% | |
6 | .\" | |
7 | .TH GREP 1 8/11/80 | |
8 | .UC 4 | |
9 | .SH NAME | |
10 | grep, egrep, fgrep \- search a file for a pattern | |
11 | .SH SYNOPSIS | |
12 | .B grep | |
13 | [ option ] ... | |
14 | expression [ file ] ... | |
15 | .LP | |
16 | .B egrep | |
17 | [ option ] ... | |
18 | [ expression ] | |
19 | [ file ] ... | |
20 | .PP | |
21 | .B fgrep | |
22 | [ option ] ... | |
23 | [ strings ] | |
24 | [ file ] | |
25 | .SH DESCRIPTION | |
26 | Commands of the | |
27 | .I grep | |
28 | family search the input | |
29 | .I files | |
30 | (standard input default) | |
31 | for lines matching | |
32 | a pattern. | |
33 | Normally, each line found | |
34 | is copied to the standard output. | |
35 | .I Grep | |
36 | patterns are limited regular expressions in the style of | |
37 | .IR ex (1); | |
38 | it uses a compact nondeterministic algorithm. | |
39 | .I Egrep | |
40 | patterns are full regular expressions; | |
41 | it uses a fast deterministic algorithm that | |
42 | sometimes needs exponential space. | |
43 | .I Fgrep | |
44 | patterns are fixed strings; it is fast and compact. | |
45 | The following options are recognized. | |
46 | .TP | |
47 | .B \-v | |
48 | All lines but those matching | |
49 | are printed. | |
50 | .TP | |
51 | .B \-x | |
52 | (Exact) only lines matched in their entirety are printed | |
53 | .RI ( fgrep | |
54 | only). | |
55 | .TP | |
56 | .B \-c | |
57 | Only a count of matching lines is printed. | |
58 | .TP | |
59 | .B \-l | |
60 | The names of files with matching lines are listed (once) | |
61 | separated by newlines. | |
62 | .TP | |
63 | .B \-n | |
64 | Each line is preceded by | |
65 | its relative line number in the file. | |
66 | .TP | |
67 | .B \-b | |
68 | Each line is preceded by the block number | |
69 | on which it was found. | |
70 | This is sometimes useful in locating | |
71 | disk block numbers by context. | |
72 | .TP | |
73 | .B \-i | |
74 | The case of letters is ignored in making comparisons. | |
75 | (E.g. upper and lower case are considered identical.) | |
76 | (\fIgrep\fR\| and \fIfgrep\fR only) | |
77 | .TP | |
78 | .B \-s | |
79 | Silent mode. | |
80 | Nothing is printed (except error messages). | |
81 | This is useful for checking the error status. | |
82 | .TP | |
83 | .B \-w | |
84 | The expression is searched for as a word | |
85 | (as if surrounded by `\e<' and `\e>', see | |
86 | .IR ex (1).) | |
87 | (\fIgrep\fR\| only) | |
88 | .TP | |
89 | .BI \-e " expression" | |
90 | Same as a simple | |
91 | .I expression | |
92 | argument, | |
93 | but useful when the | |
94 | .I expression | |
95 | begins with a \-. | |
96 | .TP | |
97 | .BI \-f " file" | |
98 | The regular expression | |
99 | .RI ( egrep ) | |
100 | or string list | |
101 | .RI ( fgrep ) | |
102 | is taken from the | |
103 | .I file. | |
104 | .PP | |
105 | In all cases the file name is shown if there is more than one input file. | |
106 | Care should be taken when | |
107 | using the characters | |
108 | $ * [ ^ | ( ) and \\ in the | |
109 | .I expression | |
110 | as they are | |
111 | also meaningful to the Shell. | |
112 | It is safest to enclose the | |
113 | entire | |
114 | .I expression | |
115 | argument in single quotes \' \'. | |
116 | .PP | |
117 | .I Fgrep | |
118 | searches for lines that contain one of the (newline-separated) | |
119 | .I strings. | |
120 | .PP | |
121 | .I Egrep | |
122 | accepts extended regular expressions. | |
123 | In the following description `character' excludes | |
124 | newline: | |
125 | .IP | |
126 | A \e followed by a single character | |
127 | other than newline | |
128 | matches that character. | |
129 | .IP | |
130 | The character ^ ($) matches the beginning (end) of | |
131 | a line. | |
132 | .IP | |
133 | A | |
134 | .B . | |
135 | matches any character. | |
136 | .IP | |
137 | A single character not otherwise endowed with special | |
138 | meaning matches that character. | |
139 | .IP | |
140 | A string enclosed in brackets [\|] | |
141 | matches any single character from the string. | |
142 | Ranges of ASCII character codes may be abbreviated | |
143 | as in `a\-z0\-9'. | |
144 | A ] | |
145 | may occur only as the first character of the string. | |
146 | A literal \- must be placed where it can't be | |
147 | mistaken as a range indicator. | |
148 | .IP | |
149 | A regular expression followed by * (+, ?) matches a sequence | |
150 | of 0 or more (1 or more, 0 or 1) | |
151 | matches of the regular expression. | |
152 | .IP | |
153 | Two regular expressions concatenated | |
154 | match a match of the first followed by a match of | |
155 | the second. | |
156 | .IP | |
157 | Two regular expressions separated by | or newline | |
158 | match either a match for the first or a match for the | |
159 | second. | |
160 | .IP | |
161 | A regular expression enclosed in parentheses | |
162 | matches a match for the regular expression. | |
163 | .LP | |
164 | The order of precedence of operators | |
165 | at the same parenthesis level | |
166 | is [\|] then | |
167 | *+? then concatenation then | and newline. | |
168 | .SH "SEE ALSO" | |
169 | ex(1), | |
170 | sed(1), | |
171 | sh(1) | |
172 | .SH DIAGNOSTICS | |
173 | Exit status is 0 if any matches are found, | |
174 | 1 if none, 2 for syntax errors or inaccessible files. | |
175 | .SH BUGS | |
176 | Ideally there should be only one | |
177 | .I grep, | |
178 | but we don't know a single algorithm that spans a wide enough | |
179 | range of space-time tradeoffs. | |
180 | .PP | |
181 | Lines | |
182 | are limited to 256 characters; | |
183 | longer lines are truncated. |