Commit | Line | Data |
---|---|---|
d9d7a9f0 CL |
1 | .\" Copyright (c) 1980, 1990 The Regents of the University of California. |
2 | .\" All rights reserved. | |
732dc260 | 3 | .\" |
d9d7a9f0 | 4 | .\" %sccs.include.redist.man% |
732dc260 | 5 | .\" |
5325ced3 | 6 | .\" @(#)grep.1 6.5 (Berkeley) %G% |
d9d7a9f0 CL |
7 | .\" |
8 | .Dd | |
9 | .Dt GREP 1 | |
10 | .Os BSD 4.4 | |
11 | .Sh NAME | |
12 | .Nm grep | |
13 | .Nd file pattern searcher | |
14 | .Sh SYNOPSIS | |
15 | .Nm grep | |
16 | .Op Fl bchilnosvw | |
17 | .Op Fl e Ar pattern | |
18 | .Ar | |
19 | .Nm egrep | |
20 | .Op Fl bchilnosv | |
21 | .Op Fl e Ar pattern | |
22 | .Op Fl f Ar pattern_file | |
23 | .Ar | |
24 | .Nm fgrep | |
25 | .Op Fl bchilnosvx | |
26 | .Op Fl e Ar pattern | |
27 | .Op Fl f Ar pattern_file | |
28 | .Ar | |
29 | .Sh DESCRIPTION | |
30 | The | |
31 | .Nm grep | |
32 | utilities search the given input files selecting lines | |
33 | which match one or more patterns; the type of patterns is controlled | |
34 | by the options specified. | |
35 | By default, a pattern | |
36 | matches an input line if any regular expression (RE) in the | |
37 | pattern matches the input line without its trailing <new-line>. | |
38 | A null RE matches every line. | |
39 | Each input line that matches at | |
40 | least one of the patterns is written to the standard output. | |
41 | .Pp | |
42 | For simple patterns or | |
43 | .Xr ex 1 | |
44 | or | |
45 | .Xr ed 1 | |
46 | style regular expressions, the | |
47 | .Nm grep | |
48 | utility is used. | |
49 | The | |
50 | .Nm egrep | |
51 | utility | |
52 | can handle extended regular expressions and | |
53 | embedded <newline>s in pattern | |
54 | .Nm Fgrep | |
55 | is quick but is designed to handle fixed strings. | |
56 | A fixed string | |
57 | is a string of characters, | |
58 | each character | |
59 | is matched only by itself. | |
60 | The pattern | |
61 | value can consist of multiple lines with | |
62 | embedded <newline>s. | |
63 | In this case, the <newline>s | |
64 | act as alternation characters, allowing any of the | |
65 | pattern lines to match a portion of the input. | |
66 | .Pp | |
67 | The following options are available: | |
68 | .Pp | |
69 | .Tw Fl | |
70 | .Tp Fl b | |
71 | The block number on the disk in which a matched pattern is located | |
72 | is displayed in front of the respective matched line. | |
73 | .Tp Fl c | |
74 | Only a count of selected lines is written to standard | |
75 | output. | |
76 | .Tc Fl e | |
77 | .Ws | |
78 | .Ar expression | |
79 | .Cx | |
80 | Specify a pattern used during the search of the | |
81 | input. | |
82 | Multiple | |
83 | .Fl e | |
84 | options can be used to specify | |
85 | multiple patterns; an input line is selected of it | |
86 | matches any of the specified patterns. | |
87 | .Tc Fl f | |
88 | .Ws | |
89 | .Ar pattern_file | |
90 | .Cx | |
91 | The pattern is read from the file named by the | |
92 | pathname pattern_file. | |
93 | Trailing newlines | |
94 | in the pattern_file are ignored. | |
95 | .Pf \&( Nm egrep | |
96 | and | |
97 | .Nm fgrep | |
732dc260 | 98 | only). |
d9d7a9f0 | 99 | .Tp Fl h |
75288a28 | 100 | Never print filename headers with output lines. |
d9d7a9f0 CL |
101 | .Tp Fl i |
102 | The case of letters is ignored in making comparisons \- that is, upper and | |
0887f810 | 103 | lower case are considered identical. |
d9d7a9f0 CL |
104 | .Tp Fl l |
105 | Only the names of files containing selected lines | |
106 | are written to standard output. | |
107 | Pathnames are | |
108 | listed once per file searched. | |
109 | If the standard | |
110 | input is searched, the pathname | |
5325ced3 | 111 | .Sq Fl |
d9d7a9f0 CL |
112 | is written. |
113 | .Tp Fl n | |
114 | Each output line is preceded by its relative line | |
115 | number in the file; each file starting at line 1. | |
116 | The line number counter is reset for each file processed. | |
117 | This option is ignored if | |
118 | .Fl c , | |
119 | .Fl l , | |
120 | or | |
121 | .Fl s | |
122 | is | |
123 | specified. | |
124 | .Tp Fl o | |
125 | Always print filename headers with output lines. | |
126 | .Tp Fl s | |
eb0cef48 | 127 | Silent mode. Nothing is printed (except error messages). |
732dc260 | 128 | This is useful for checking the error status. |
d9d7a9f0 CL |
129 | .Tp Fl v |
130 | Selected lines are those | |
131 | .Em not | |
132 | matching the specified | |
133 | patterns. | |
134 | .Tp Fl x | |
135 | Only input lines selected against an entire fixed | |
136 | string or regular expression are considered to be | |
137 | matching lines. | |
138 | .Pf \&( Nm fgrep | |
139 | only). | |
140 | .Tp Fl w | |
732dc260 KM |
141 | The expression is searched for as a word |
142 | (as if surrounded by `\e<' and `\e>', see | |
d9d7a9f0 CL |
143 | .Xr ex 1 . ) |
144 | .Pf \&( Nm grep | |
145 | only) | |
146 | .Pp | |
147 | .Tp | |
148 | If no file arguments are specified, the | |
149 | standard input is used. | |
150 | .Pp | |
151 | The | |
152 | .Nm grep | |
153 | utility exits with one of the following values: | |
5325ced3 CL |
154 | .Dw Ds |
155 | .Dp Li \&0 | |
d9d7a9f0 | 156 | One or more lines were selected. |
5325ced3 | 157 | .Dp Li \&1 |
d9d7a9f0 | 158 | No lines were selected. |
5325ced3 | 159 | .Dp Li \&>1 |
d9d7a9f0 | 160 | An error occurred. |
5325ced3 | 161 | .Dp |
d9d7a9f0 CL |
162 | .Sh EXTENDED REGULAR EXPRESSIONS |
163 | The following characters are interpreted by | |
164 | .Nm egrep : | |
165 | .Tw Ds | |
166 | .Tp Cm \&$ | |
167 | Align the match from the end of the line. | |
168 | .Tp Cm \&^ | |
169 | Align the match from the beginning of the line. | |
170 | .Tp Cm \&| | |
171 | Add another pattern (see example below). | |
172 | .Tp Cm \&? | |
173 | Match 1 or less sequential repetitions of the pattern. | |
174 | .Tp Cm \&+ | |
175 | Match 1 or more sequential repetitions of the pattern. | |
176 | .Tp Cm \&* | |
177 | Match 0 or more sequential repetitions of the pattern. | |
178 | .Tp Cm \&[] | |
179 | Match any single character or range of characters | |
180 | enclosed in the brackets. | |
181 | .Tp Cm \&\e | |
182 | Escape special characters which have meaning to | |
183 | .Nm egrep , | |
184 | the set of {$,.,^,[,],|,?,+,*,(,)}. | |
185 | .Tp | |
186 | .Sh EXAMPLES | |
187 | To find all occurances of the word patricia in a file: | |
5325ced3 | 188 | .Pp |
d9d7a9f0 CL |
189 | .Dl grep patricia myfile |
190 | .Pp | |
191 | To find all occurences to the pattern | |
192 | .Sq Li \&.Pp | |
193 | at the beginning of a line: | |
5325ced3 | 194 | .Pp |
d9d7a9f0 CL |
195 | .Dl grep '^\e.Pp' |
196 | .Pp | |
197 | The apostrophys assure the entire expression is evaluated by | |
198 | .Nm grep | |
199 | instead of by the | |
200 | users shell. | |
201 | The carat or hat | |
202 | .Sq Li \&^ | |
203 | means | |
204 | .Em from the beginning of a line , | |
205 | and the | |
206 | .Sq Li \&\e | |
207 | escapes the | |
208 | .Sq Li \&. | |
209 | which would otherwise match any character. | |
210 | .Pp | |
211 | A simple example of an extended regular expression: | |
5325ced3 | 212 | .Pp |
d9d7a9f0 CL |
213 | .Dl egrep '19|20|25' calendar |
214 | .Pp | |
215 | Peruses the file calendar looking for either 19, 20 | |
216 | or 25. | |
217 | .Sh SEE ALSO | |
218 | .Xr ed 1 , | |
219 | .Xr ex 1 , | |
220 | .Xr sed 1 | |
221 | .Sh HISTORY | |
222 | .Nm Grep | |
223 | appeared in Version 6 AT&T Unix. | |
224 | .Sh BUGS | |
eb0cef48 | 225 | Lines are limited to 256 characters; longer lines are truncated. |