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