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 | .\" | |
75288a28 | 5 | .\" @(#)grep.1 6.3 (Berkeley) %G% |
732dc260 | 6 | .\" |
5c7ef023 | 7 | .TH GREP 1 "" |
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 | 63 | .TP |
75288a28 KB |
64 | .B \-h |
65 | Never print filename headers with output lines. | |
66 | .TP | |
67 | .B \-o | |
68 | Always print filename headers with output lines. | |
69 | .TP | |
732dc260 | 70 | .B \-i |
eb0cef48 | 71 | The case of letters is ignored in making comparisons \(em that is, upper and |
0887f810 | 72 | lower case are considered identical. |
732dc260 KM |
73 | .TP |
74 | .B \-s | |
eb0cef48 | 75 | Silent mode. Nothing is printed (except error messages). |
732dc260 KM |
76 | This is useful for checking the error status. |
77 | .TP | |
78 | .B \-w | |
79 | The expression is searched for as a word | |
80 | (as if surrounded by `\e<' and `\e>', see | |
81 | .IR ex (1).) | |
82 | (\fIgrep\fR\| only) | |
83 | .TP | |
84 | .BI \-e " expression" | |
85 | Same as a simple | |
86 | .I expression | |
eb0cef48 | 87 | argument, but useful when the |
732dc260 KM |
88 | .I expression |
89 | begins with a \-. | |
90 | .TP | |
91 | .BI \-f " file" | |
75288a28 | 92 | The regular expression (\fIegrep\fP) or string list |
732dc260 KM |
93 | .RI ( fgrep ) |
94 | is taken from the | |
95 | .I file. | |
eb0cef48 | 96 | .LP |
732dc260 | 97 | In all cases the file name is shown if there is more than one input file. |
eb0cef48 | 98 | Care should be taken when using the characters $ * [ ^ | ( ) and \\ in the |
732dc260 | 99 | .I expression |
eb0cef48 | 100 | as they are also meaningful to the Shell. It is safest to enclose the entire |
732dc260 KM |
101 | .I expression |
102 | argument in single quotes \' \'. | |
eb0cef48 | 103 | .LP |
732dc260 KM |
104 | .I Fgrep |
105 | searches for lines that contain one of the (newline-separated) | |
106 | .I strings. | |
eb0cef48 | 107 | .LP |
732dc260 KM |
108 | .I Egrep |
109 | accepts extended regular expressions. | |
eb0cef48 | 110 | In the following description `character' excludes newline: |
732dc260 | 111 | .IP |
eb0cef48 | 112 | A \e followed by a single character other than newline matches that character. |
732dc260 | 113 | .IP |
eb0cef48 KM |
114 | The character ^ matches the beginning of a line. |
115 | .IP | |
116 | The character $ matches the end of a line. | |
732dc260 KM |
117 | .IP |
118 | A | |
119 | .B . | |
eb0cef48 | 120 | (period) matches any character. |
732dc260 KM |
121 | .IP |
122 | A single character not otherwise endowed with special | |
123 | meaning matches that character. | |
124 | .IP | |
eb0cef48 KM |
125 | A string enclosed in brackets [\|] matches any single character from the string. |
126 | Ranges of ASCII character codes may be abbreviated as in `a\-z0\-9'. | |
732dc260 KM |
127 | A ] |
128 | may occur only as the first character of the string. | |
eb0cef48 | 129 | A literal \- must be placed where it can't be mistaken as a range indicator. |
732dc260 | 130 | .IP |
eb0cef48 KM |
131 | A regular expression followed by an * (asterisk) matches a sequence of 0 |
132 | or more matches of the regular expression. | |
133 | A regular expression followed by a + (plus) matches a sequence of 1 or more | |
732dc260 | 134 | matches of the regular expression. |
eb0cef48 KM |
135 | A regular expression followed by a ? (question mark) matches a sequence of |
136 | 0 or 1 matches of the regular expression. | |
732dc260 | 137 | .IP |
eb0cef48 KM |
138 | Two regular expressions concatenated match a match of the first followed |
139 | by a match of the second. | |
732dc260 KM |
140 | .IP |
141 | Two regular expressions separated by | or newline | |
eb0cef48 | 142 | match either a match for the first or a match for the second. |
732dc260 KM |
143 | .IP |
144 | A regular expression enclosed in parentheses | |
145 | matches a match for the regular expression. | |
146 | .LP | |
eb0cef48 KM |
147 | The order of precedence of operators at the same parenthesis level |
148 | is [\|] then *+? then concatenation then | and newline. | |
149 | .LP | |
150 | Ideally there should be only one | |
151 | .I grep, | |
152 | but we don't know a single algorithm that spans a wide enough | |
153 | range of space-time tradeoffs. | |
732dc260 KM |
154 | .SH "SEE ALSO" |
155 | ex(1), | |
156 | sed(1), | |
157 | sh(1) | |
158 | .SH DIAGNOSTICS | |
159 | Exit status is 0 if any matches are found, | |
160 | 1 if none, 2 for syntax errors or inaccessible files. | |
161 | .SH BUGS | |
eb0cef48 | 162 | Lines are limited to 256 characters; longer lines are truncated. |