1 .\" $NetBSD: grep.1,v 1.7 2003/11/05 16:39:01 cjep Exp $
3 .\" Copyright (c) 1980, 1990, 1993
4 .\" The Regents of the University of California. All rights reserved.
6 .\" Redistribution and use in source and binary forms, with or without
7 .\" modification, are permitted provided that the following conditions
9 .\" 1. Redistributions of source code must retain the above copyright
10 .\" notice, this list of conditions and the following disclaimer.
11 .\" 2. Redistributions in binary form must reproduce the above copyright
12 .\" notice, this list of conditions and the following disclaimer in the
13 .\" documentation and/or other materials provided with the distribution.
14 .\" 3. All advertising materials mentioning features or use of this software
15 .\" must display the following acknowledgement:
16 .\" This product includes software developed by the University of
17 .\" California, Berkeley and its contributors.
18 .\" 4. Neither the name of the University nor the names of its contributors
19 .\" may be used to endorse or promote products derived from this software
20 .\" without specific prior written permission.
22 .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34 .\" @(#)grep.1 8.3 (Berkeley) 4/18/94
40 .Nm grep, egrep, fgrep, zgrep
41 .Nd file pattern searcher
45 .Op Fl EFGHILPSVZabchilnqrsvwxz
53 utilities search the given input files selecting lines that match one
55 By default, a pattern matches an input line if any regular expression
56 (RE) in the pattern matches the input line without its trailing
58 An empty expression matches every line.
59 Each input line that matches at least one of the patterns is written
60 to the standard output.
64 utility is used for simple patterns and
68 style regular expressions.
71 utility can handle extended regular expressions and multi-line
75 utility is quick but can handle only fixed patterns consisting of one
76 or more lines, allowing any of the pattern lines to match a portion of
80 utility acts like grep, but accepts input files compressed with the
84 compression utilities.
86 The following options are available:
88 .Bl -tag -width indent
92 lines of trailing context after each match.
96 lines of leading context before each match.
100 lines of leading and trailing context before and after each match
103 Use the specified action when processing input files that are devices, FIFOs
105 The default action is
107 which means that that devices are treated as ordinary files. If the action is
109 then devices will not be processed at all.
126 Always print filename headers with output lines.
128 If the file being processed is binary, assume that it does not contain
131 Only the names of files not containing selected lines are written to
133 Pathnames are listed once per file searched.
134 If the standard input is searched, the pathname
140 is specified, no symbolic links are followed.
144 is specified, all symbolic links are followed.
146 Display version information.
148 When printing filenames, output a null character after the filename instead of
151 Treat all files as text.
153 The block number on the disk in which a matched pattern is located is
154 displayed in front of the respective matched line.
156 Only a count of selected lines is written to standard output.
158 Use the specified action when processing input files that are directories.
159 The default action is
161 which means that directories are treated as ordinary files. If the action is
163 then directories will not be processed at all. If the action is
167 will read all files under each directory recursively.
168 .It Fl e Ar expression
169 Specify a pattern used during the search of the input. Multiple
171 options can be used to specify multiple patterns; an input line is
172 selected if it matches any of the specified patterns.
173 .It Fl f Ar pattern_file
174 The pattern is read from the specified file. Trailing newlines in the
175 pattern file are ignored.
181 Never print filename headers with output lines.
183 Perform case insensitive matching.
185 Only the names of files containing selected lines are written to
186 standard output. Pathnames are listed once per file searched. If the
187 standard input is searched, the pathname
191 Each output line is preceded by its relative line number in the file,
193 The line number counter is reset for each file processed.
194 This option is ignored if
202 Suppress normal output.
204 Recursively search subdirectories listed.
206 Silent mode. Nonexistent and unreadable files are ignored.
208 Selected lines are those
210 matching the specified
213 The expression is searched for as a word (as if surrounded by `\e<'
217 Only input lines selected against an entire fixed string or regular
218 expression are considered to be matching lines.
220 When printing matched lines, output a null character after the line instead of
224 If no file arguments are specified, the standard input is used.
228 utility exits with one of the following values:
230 .Bl -tag -width flag -compact
232 One or more lines were selected.
234 No lines were selected.
238 .Sh EXTENDED REGULAR EXPRESSIONS
239 The following characters are interpreted by
242 .Bl -tag -width flag -compact
244 Align the match from the end of the line.
246 Align the match from the beginning of the line.
248 Add another pattern (see example below).
250 Match 1 or less sequential repetitions of the pattern.
252 Match 1 or more sequential repetitions of the pattern.
254 Match 0 or more sequential repetitions of the pattern.
256 Match any single character or range of characters
257 enclosed in the brackets.
259 Escape special characters which have meaning to
261 the set of {$,.,^,[,],|,?,+,*,(,)}.
264 To find all occurrences of the word patricia in a file:
266 .Dl grep patricia myfile
268 To find all occurrences of the pattern
270 at the beginning of a line:
274 The apostrophes assure the entire expression is evaluated by
280 matches the null string at the beginning of a line,
285 which would otherwise match any character.
287 A simple example of an extended regular expression:
289 .Dl egrep '19|20|25' calendar
291 Peruses the file calendar looking for either 19, 20