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