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