xref: /freebsd/usr.bin/grep/grep.1 (revision 4dc88ebedf943d69252e1bb441d756cf85540592)
1*4dc88ebeSGabor Kovesdan.\"	$FreeBSD$
2*4dc88ebeSGabor Kovesdan.\"	$OpenBSD: grep.1,v 1.38 2010/04/05 06:30:59 jmc Exp $
3*4dc88ebeSGabor Kovesdan.\" Copyright (c) 1980, 1990, 1993
4*4dc88ebeSGabor Kovesdan.\"	The Regents of the University of California.  All rights reserved.
5*4dc88ebeSGabor Kovesdan.\"
6*4dc88ebeSGabor Kovesdan.\" Redistribution and use in source and binary forms, with or without
7*4dc88ebeSGabor Kovesdan.\" modification, are permitted provided that the following conditions
8*4dc88ebeSGabor Kovesdan.\" are met:
9*4dc88ebeSGabor Kovesdan.\" 1. Redistributions of source code must retain the above copyright
10*4dc88ebeSGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer.
11*4dc88ebeSGabor Kovesdan.\" 2. Redistributions in binary form must reproduce the above copyright
12*4dc88ebeSGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer in the
13*4dc88ebeSGabor Kovesdan.\"    documentation and/or other materials provided with the distribution.
14*4dc88ebeSGabor Kovesdan.\" 3. Neither the name of the University nor the names of its contributors
15*4dc88ebeSGabor Kovesdan.\"    may be used to endorse or promote products derived from this software
16*4dc88ebeSGabor Kovesdan.\"    without specific prior written permission.
17*4dc88ebeSGabor Kovesdan.\"
18*4dc88ebeSGabor Kovesdan.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19*4dc88ebeSGabor Kovesdan.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20*4dc88ebeSGabor Kovesdan.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21*4dc88ebeSGabor Kovesdan.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22*4dc88ebeSGabor Kovesdan.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23*4dc88ebeSGabor Kovesdan.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24*4dc88ebeSGabor Kovesdan.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25*4dc88ebeSGabor Kovesdan.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26*4dc88ebeSGabor Kovesdan.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27*4dc88ebeSGabor Kovesdan.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28*4dc88ebeSGabor Kovesdan.\" SUCH DAMAGE.
29*4dc88ebeSGabor Kovesdan.\"
30*4dc88ebeSGabor Kovesdan.\"	@(#)grep.1	8.3 (Berkeley) 4/18/94
31*4dc88ebeSGabor Kovesdan.\"
32*4dc88ebeSGabor Kovesdan.Dd 19 September, 2009
33*4dc88ebeSGabor Kovesdan.Dt GREP 1
34*4dc88ebeSGabor Kovesdan.Os
35*4dc88ebeSGabor Kovesdan.Sh NAME
36*4dc88ebeSGabor Kovesdan.Nm grep , egrep , fgrep ,
37*4dc88ebeSGabor Kovesdan.Nm zgrep , zegrep , zfgrep
38*4dc88ebeSGabor Kovesdan.Nd file pattern searcher
39*4dc88ebeSGabor Kovesdan.Sh SYNOPSIS
40*4dc88ebeSGabor Kovesdan.Nm grep
41*4dc88ebeSGabor Kovesdan.Bk -words
42*4dc88ebeSGabor Kovesdan.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZ
43*4dc88ebeSGabor Kovesdan.Op Fl A Ar num
44*4dc88ebeSGabor Kovesdan.Op Fl B Ar num
45*4dc88ebeSGabor Kovesdan.Op Fl C Ns Op Ar num
46*4dc88ebeSGabor Kovesdan.Op Fl e Ar pattern
47*4dc88ebeSGabor Kovesdan.Op Fl f Ar file
48*4dc88ebeSGabor Kovesdan.Op Fl Fl binary-files Ns = Ns Ar value
49*4dc88ebeSGabor Kovesdan.Op Fl Fl color Ns Op = Ns Ar when
50*4dc88ebeSGabor Kovesdan.Op Fl Fl colour Ns Op = Ns Ar when
51*4dc88ebeSGabor Kovesdan.Op Fl Fl context Ns Op = Ns Ar num
52*4dc88ebeSGabor Kovesdan.Op Fl Fl label
53*4dc88ebeSGabor Kovesdan.Op Fl Fl line-buffered
54*4dc88ebeSGabor Kovesdan.Op Fl Fl null
55*4dc88ebeSGabor Kovesdan.Op Ar pattern
56*4dc88ebeSGabor Kovesdan.Op Ar
57*4dc88ebeSGabor Kovesdan.Ek
58*4dc88ebeSGabor Kovesdan.Sh DESCRIPTION
59*4dc88ebeSGabor KovesdanThe
60*4dc88ebeSGabor Kovesdan.Nm grep
61*4dc88ebeSGabor Kovesdanutility searches any given input files,
62*4dc88ebeSGabor Kovesdanselecting lines that match one or more patterns.
63*4dc88ebeSGabor KovesdanBy default, a pattern matches an input line if the regular expression
64*4dc88ebeSGabor Kovesdan(RE) in the pattern matches the input line
65*4dc88ebeSGabor Kovesdanwithout its trailing newline.
66*4dc88ebeSGabor KovesdanAn empty expression matches every line.
67*4dc88ebeSGabor KovesdanEach input line that matches at least one of the patterns is written
68*4dc88ebeSGabor Kovesdanto the standard output.
69*4dc88ebeSGabor Kovesdan.Pp
70*4dc88ebeSGabor Kovesdan.Nm grep
71*4dc88ebeSGabor Kovesdanis used for simple patterns and
72*4dc88ebeSGabor Kovesdanbasic regular expressions
73*4dc88ebeSGabor Kovesdan.Pq BREs ;
74*4dc88ebeSGabor Kovesdan.Nm egrep
75*4dc88ebeSGabor Kovesdancan handle extended regular expressions
76*4dc88ebeSGabor Kovesdan.Pq EREs .
77*4dc88ebeSGabor KovesdanSee
78*4dc88ebeSGabor Kovesdan.Xr re_format 7
79*4dc88ebeSGabor Kovesdanfor more information on regular expressions.
80*4dc88ebeSGabor Kovesdan.Nm fgrep
81*4dc88ebeSGabor Kovesdanis quicker than both
82*4dc88ebeSGabor Kovesdan.Nm grep
83*4dc88ebeSGabor Kovesdanand
84*4dc88ebeSGabor Kovesdan.Nm egrep ,
85*4dc88ebeSGabor Kovesdanbut can only handle fixed patterns
86*4dc88ebeSGabor Kovesdan(i.e. it does not interpret regular expressions).
87*4dc88ebeSGabor KovesdanPatterns may consist of one or more lines,
88*4dc88ebeSGabor Kovesdanallowing any of the pattern lines to match a portion of the input.
89*4dc88ebeSGabor Kovesdan.Pp
90*4dc88ebeSGabor Kovesdan.Nm zgrep ,
91*4dc88ebeSGabor Kovesdan.Nm zegrep ,
92*4dc88ebeSGabor Kovesdanand
93*4dc88ebeSGabor Kovesdan.Nm zfgrep
94*4dc88ebeSGabor Kovesdanact like
95*4dc88ebeSGabor Kovesdan.Nm grep ,
96*4dc88ebeSGabor Kovesdan.Nm egrep ,
97*4dc88ebeSGabor Kovesdanand
98*4dc88ebeSGabor Kovesdan.Nm fgrep ,
99*4dc88ebeSGabor Kovesdanrespectively, but accept input files compressed with the
100*4dc88ebeSGabor Kovesdan.Xr compress 1
101*4dc88ebeSGabor Kovesdanor
102*4dc88ebeSGabor Kovesdan.Xr gzip 1
103*4dc88ebeSGabor Kovesdancompression utilities.
104*4dc88ebeSGabor Kovesdan.Pp
105*4dc88ebeSGabor KovesdanThe following options are available:
106*4dc88ebeSGabor Kovesdan.Bl -tag -width indent
107*4dc88ebeSGabor Kovesdan.It Fl A Ar num , Fl Fl after-context Ns = Ns Ar num
108*4dc88ebeSGabor KovesdanPrint
109*4dc88ebeSGabor Kovesdan.Ar num
110*4dc88ebeSGabor Kovesdanlines of trailing context after each match.
111*4dc88ebeSGabor KovesdanSee also the
112*4dc88ebeSGabor Kovesdan.Fl B
113*4dc88ebeSGabor Kovesdanand
114*4dc88ebeSGabor Kovesdan.Fl C
115*4dc88ebeSGabor Kovesdanoptions.
116*4dc88ebeSGabor Kovesdan.It Fl a , Fl Fl text
117*4dc88ebeSGabor KovesdanTreat all files as ASCII text.
118*4dc88ebeSGabor KovesdanNormally
119*4dc88ebeSGabor Kovesdan.Nm
120*4dc88ebeSGabor Kovesdanwill simply print
121*4dc88ebeSGabor Kovesdan.Dq Binary file ... matches
122*4dc88ebeSGabor Kovesdanif files contain binary characters.
123*4dc88ebeSGabor KovesdanUse of this option forces
124*4dc88ebeSGabor Kovesdan.Nm
125*4dc88ebeSGabor Kovesdanto output lines matching the specified pattern.
126*4dc88ebeSGabor Kovesdan.It Fl B Ar num , Fl Fl before-context Ns = Ns Ar num
127*4dc88ebeSGabor KovesdanPrint
128*4dc88ebeSGabor Kovesdan.Ar num
129*4dc88ebeSGabor Kovesdanlines of leading context before each match.
130*4dc88ebeSGabor KovesdanSee also the
131*4dc88ebeSGabor Kovesdan.Fl A
132*4dc88ebeSGabor Kovesdanand
133*4dc88ebeSGabor Kovesdan.Fl C
134*4dc88ebeSGabor Kovesdanoptions.
135*4dc88ebeSGabor Kovesdan.It Fl b , Fl Fl byte-offset
136*4dc88ebeSGabor KovesdanThe offset in bytes of a matched pattern is
137*4dc88ebeSGabor Kovesdandisplayed in front of the respective matched line.
138*4dc88ebeSGabor Kovesdan.It Fl C Ns Op Ar num , Fl Fl context Ns = Ns Ar num
139*4dc88ebeSGabor KovesdanPrint
140*4dc88ebeSGabor Kovesdan.Ar num
141*4dc88ebeSGabor Kovesdanlines of leading and trailing context surrounding each match.
142*4dc88ebeSGabor KovesdanThe default is 2 and is equivalent to
143*4dc88ebeSGabor Kovesdan.Fl A
144*4dc88ebeSGabor Kovesdan.Ar 2
145*4dc88ebeSGabor Kovesdan.Fl B
146*4dc88ebeSGabor Kovesdan.Ar 2 .
147*4dc88ebeSGabor KovesdanNote:
148*4dc88ebeSGabor Kovesdanno whitespace may be given between the option and its argument.
149*4dc88ebeSGabor Kovesdan.It Fl c , Fl Fl count
150*4dc88ebeSGabor KovesdanOnly a count of selected lines is written to standard output.
151*4dc88ebeSGabor Kovesdan.It Fl Fl colour Ns = Ns Op Ar when , Fl Fl color Ns = Ns Op Ar when
152*4dc88ebeSGabor KovesdanMark up the matching text with the expression stored in
153*4dc88ebeSGabor Kovesdan.Ev GREP_COLOR
154*4dc88ebeSGabor Kovesdanenvironment variable.
155*4dc88ebeSGabor KovesdanThe possible values of when can be `never', `always' or `auto'.
156*4dc88ebeSGabor Kovesdan.It Fl D Ar action , Fl Fl devices Ns = Ns Ar action
157*4dc88ebeSGabor KovesdanSpecify the demanded action for devices, FIFOs and sockets.
158*4dc88ebeSGabor KovesdanThe default action is `read', which means, that they are read
159*4dc88ebeSGabor Kovesdanas if they were normal files.
160*4dc88ebeSGabor KovesdanIf the action is set to `skip', devices will be silently skipped.
161*4dc88ebeSGabor Kovesdan.It Fl d Ar action , Fl Fl directories Ns = Ns Ar action
162*4dc88ebeSGabor KovesdanSpecify the demanded action for directories.
163*4dc88ebeSGabor KovesdanIt is `read' by default, which means that the directories
164*4dc88ebeSGabor Kovesdanare read in the same manner as normal files.
165*4dc88ebeSGabor KovesdanOther possible values are `skip' to silently ignore the
166*4dc88ebeSGabor Kovesdandirectories, and `recurse' to read them recursively, which
167*4dc88ebeSGabor Kovesdanhas the same effect as the
168*4dc88ebeSGabor Kovesdan.Fl R
169*4dc88ebeSGabor Kovesdanand
170*4dc88ebeSGabor Kovesdan.Fl r
171*4dc88ebeSGabor Kovesdanoption.
172*4dc88ebeSGabor Kovesdan.It Fl E , Fl Fl extended-regexp
173*4dc88ebeSGabor KovesdanInterpret
174*4dc88ebeSGabor Kovesdan.Ar pattern
175*4dc88ebeSGabor Kovesdanas an extended regular expression
176*4dc88ebeSGabor Kovesdan(i.e. force
177*4dc88ebeSGabor Kovesdan.Nm grep
178*4dc88ebeSGabor Kovesdanto behave as
179*4dc88ebeSGabor Kovesdan.Nm egrep ) .
180*4dc88ebeSGabor Kovesdan.It Fl e Ar pattern , Fl Fl regexp Ns = Ns Ar pattern
181*4dc88ebeSGabor KovesdanSpecify a pattern used during the search of the input:
182*4dc88ebeSGabor Kovesdanan input line is selected if it matches any of the specified patterns.
183*4dc88ebeSGabor KovesdanThis option is most useful when multiple
184*4dc88ebeSGabor Kovesdan.Fl e
185*4dc88ebeSGabor Kovesdanoptions are used to specify multiple patterns,
186*4dc88ebeSGabor Kovesdanor when a pattern begins with a dash
187*4dc88ebeSGabor Kovesdan.Pq Sq - .
188*4dc88ebeSGabor Kovesdan.It Fl Fl exclude
189*4dc88ebeSGabor KovesdanIf
190*4dc88ebeSGabor Kovesdan.Fl R
191*4dc88ebeSGabor Kovesdanis specified, it excludes files matching the given
192*4dc88ebeSGabor Kovesdanfilename pattern.
193*4dc88ebeSGabor Kovesdan.It Fl Fl exclude-dir
194*4dc88ebeSGabor KovesdanIf
195*4dc88ebeSGabor Kovesdan.Fl R
196*4dc88ebeSGabor Kovesdanis specified, it excludes directories matching the
197*4dc88ebeSGabor Kovesdangiven filename pattern.
198*4dc88ebeSGabor Kovesdan.It Fl F , Fl Fl fixed-strings
199*4dc88ebeSGabor KovesdanInterpret
200*4dc88ebeSGabor Kovesdan.Ar pattern
201*4dc88ebeSGabor Kovesdanas a set of fixed strings
202*4dc88ebeSGabor Kovesdan(i.e. force
203*4dc88ebeSGabor Kovesdan.Nm grep
204*4dc88ebeSGabor Kovesdanto behave as
205*4dc88ebeSGabor Kovesdan.Nm fgrep ) .
206*4dc88ebeSGabor Kovesdan.It Fl f Ar file , Fl Fl file Ns = Ns Ar file
207*4dc88ebeSGabor KovesdanRead one or more newline separated patterns from
208*4dc88ebeSGabor Kovesdan.Ar file .
209*4dc88ebeSGabor KovesdanEmpty pattern lines match every input line.
210*4dc88ebeSGabor KovesdanNewlines are not considered part of a pattern.
211*4dc88ebeSGabor KovesdanIf
212*4dc88ebeSGabor Kovesdan.Ar file
213*4dc88ebeSGabor Kovesdanis empty, nothing is matched.
214*4dc88ebeSGabor Kovesdan.It Fl G , Fl Fl basic-regexp
215*4dc88ebeSGabor KovesdanInterpret
216*4dc88ebeSGabor Kovesdan.Ar pattern
217*4dc88ebeSGabor Kovesdanas a basic regular expression
218*4dc88ebeSGabor Kovesdan(i.e. force
219*4dc88ebeSGabor Kovesdan.Nm grep
220*4dc88ebeSGabor Kovesdanto behave as traditional
221*4dc88ebeSGabor Kovesdan.Nm grep ) .
222*4dc88ebeSGabor Kovesdan.It Fl H
223*4dc88ebeSGabor KovesdanAlways print filename headers with output lines.
224*4dc88ebeSGabor Kovesdan.It Fl h , Fl Fl no-filename
225*4dc88ebeSGabor KovesdanNever print filename headers
226*4dc88ebeSGabor Kovesdan.Pq i.e. filenames
227*4dc88ebeSGabor Kovesdanwith output lines.
228*4dc88ebeSGabor Kovesdan.It Fl Fl help
229*4dc88ebeSGabor KovesdanPrint a brief help message.
230*4dc88ebeSGabor Kovesdan.It Fl I
231*4dc88ebeSGabor KovesdanIgnore binary files.
232*4dc88ebeSGabor KovesdanThis option is equivalent to
233*4dc88ebeSGabor Kovesdan.Fl Fl binary-file Ns = Ns Ar without-match
234*4dc88ebeSGabor Kovesdanoption.
235*4dc88ebeSGabor Kovesdan.It Fl i , Fl Fl ignore-case
236*4dc88ebeSGabor KovesdanPerform case insensitive matching.
237*4dc88ebeSGabor KovesdanBy default,
238*4dc88ebeSGabor Kovesdan.Nm grep
239*4dc88ebeSGabor Kovesdanis case sensitive.
240*4dc88ebeSGabor Kovesdan.It Fl Fl include
241*4dc88ebeSGabor KovesdanIf
242*4dc88ebeSGabor Kovesdan.Fl R
243*4dc88ebeSGabor Kovesdanis specified, it includes the files matching the
244*4dc88ebeSGabor Kovesdangiven filename pattern.
245*4dc88ebeSGabor Kovesdan.It Fl Fl include-dir
246*4dc88ebeSGabor KovesdanIf
247*4dc88ebeSGabor Kovesdan.Fl R
248*4dc88ebeSGabor Kovesdanis specified, it includes the directories matching the
249*4dc88ebeSGabor Kovesdangiven filename pattern.
250*4dc88ebeSGabor Kovesdan.It Fl J, Fl Fl bz2decompress
251*4dc88ebeSGabor KovesdanDecompress the
252*4dc88ebeSGabor Kovesdan.Xr bzip2 1
253*4dc88ebeSGabor Kovesdancompressed file before looking for the text.
254*4dc88ebeSGabor Kovesdan.It Fl L , Fl Fl files-without-match
255*4dc88ebeSGabor KovesdanOnly the names of files not containing selected lines are written to
256*4dc88ebeSGabor Kovesdanstandard output.
257*4dc88ebeSGabor KovesdanPathnames are listed once per file searched.
258*4dc88ebeSGabor KovesdanIf the standard input is searched, the string
259*4dc88ebeSGabor Kovesdan.Dq (standard input)
260*4dc88ebeSGabor Kovesdanis written.
261*4dc88ebeSGabor Kovesdan.It Fl l , Fl Fl files-with-matches
262*4dc88ebeSGabor KovesdanOnly the names of files containing selected lines are written to
263*4dc88ebeSGabor Kovesdanstandard output.
264*4dc88ebeSGabor Kovesdan.Nm grep
265*4dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
266*4dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
267*4dc88ebeSGabor KovesdanPathnames are listed once per file searched.
268*4dc88ebeSGabor KovesdanIf the standard input is searched, the string
269*4dc88ebeSGabor Kovesdan.Dq (standard input)
270*4dc88ebeSGabor Kovesdanis written.
271*4dc88ebeSGabor Kovesdan.It Fl Fl mmap
272*4dc88ebeSGabor KovesdanUse
273*4dc88ebeSGabor Kovesdan.Xr mmap 2
274*4dc88ebeSGabor Kovesdaninstead of
275*4dc88ebeSGabor Kovesdan.Xr read 2
276*4dc88ebeSGabor Kovesdanto read input, which can result in better performance under some
277*4dc88ebeSGabor Kovesdancircumstances but can cause undefined behaiour.
278*4dc88ebeSGabor Kovesdan.It Fl m Ar num, Fl Fl max-count Ns = Ns Ar num
279*4dc88ebeSGabor KovesdanStop reading the file after
280*4dc88ebeSGabor Kovesdan.Ar num
281*4dc88ebeSGabor Kovesdanmatches.
282*4dc88ebeSGabor Kovesdan.It Fl n , Fl Fl line-number
283*4dc88ebeSGabor KovesdanEach output line is preceded by its relative line number in the file,
284*4dc88ebeSGabor Kovesdanstarting at line 1.
285*4dc88ebeSGabor KovesdanThe line number counter is reset for each file processed.
286*4dc88ebeSGabor KovesdanThis option is ignored if
287*4dc88ebeSGabor Kovesdan.Fl c ,
288*4dc88ebeSGabor Kovesdan.Fl L ,
289*4dc88ebeSGabor Kovesdan.Fl l ,
290*4dc88ebeSGabor Kovesdanor
291*4dc88ebeSGabor Kovesdan.Fl q
292*4dc88ebeSGabor Kovesdanis
293*4dc88ebeSGabor Kovesdanspecified.
294*4dc88ebeSGabor Kovesdan.It Fl Fl null
295*4dc88ebeSGabor KovesdanPrints a zero-byte after the file name.
296*4dc88ebeSGabor Kovesdan.It Fl O
297*4dc88ebeSGabor KovesdanIf
298*4dc88ebeSGabor Kovesdan.Fl R
299*4dc88ebeSGabor Kovesdanis specified, follow symbolic links only if they were explicitly listed
300*4dc88ebeSGabor Kovesdanon the command line.
301*4dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
302*4dc88ebeSGabor Kovesdan.It Fl o, Fl Fl only-matching
303*4dc88ebeSGabor KovesdanPrints only the matching part of the lines.
304*4dc88ebeSGabor Kovesdan.It Fl p
305*4dc88ebeSGabor KovesdanIf
306*4dc88ebeSGabor Kovesdan.Fl R
307*4dc88ebeSGabor Kovesdanis specified, no symbolic links are followed.
308*4dc88ebeSGabor KovesdanThis is the default.
309*4dc88ebeSGabor Kovesdan.It Fl q , Fl Fl quiet , Fl Fl silent
310*4dc88ebeSGabor KovesdanQuiet mode:
311*4dc88ebeSGabor Kovesdansuppress normal output.
312*4dc88ebeSGabor Kovesdan.Nm grep
313*4dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
314*4dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
315*4dc88ebeSGabor Kovesdan.It Fl R , Fl r , Fl Fl recursive
316*4dc88ebeSGabor KovesdanRecursively search subdirectories listed.
317*4dc88ebeSGabor Kovesdan.It Fl S
318*4dc88ebeSGabor KovesdanIf
319*4dc88ebeSGabor Kovesdan.Fl R
320*4dc88ebeSGabor Kovesdanis specified, all symbolic links are followed.
321*4dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
322*4dc88ebeSGabor Kovesdan.It Fl s , Fl Fl no-messages
323*4dc88ebeSGabor KovesdanSilent mode.
324*4dc88ebeSGabor KovesdanNonexistent and unreadable files are ignored
325*4dc88ebeSGabor Kovesdan(i.e. their error messages are suppressed).
326*4dc88ebeSGabor Kovesdan.It Fl U , Fl Fl binary
327*4dc88ebeSGabor KovesdanSearch binary files, but do not attempt to print them.
328*4dc88ebeSGabor Kovesdan.It Fl V , Fl Fl version
329*4dc88ebeSGabor KovesdanDisplay version information and exit.
330*4dc88ebeSGabor Kovesdan.It Fl v , Fl Fl invert-match
331*4dc88ebeSGabor KovesdanSelected lines are those
332*4dc88ebeSGabor Kovesdan.Em not
333*4dc88ebeSGabor Kovesdanmatching any of the specified patterns.
334*4dc88ebeSGabor Kovesdan.It Fl w , Fl Fl word-regexp
335*4dc88ebeSGabor KovesdanThe expression is searched for as a word (as if surrounded by
336*4dc88ebeSGabor Kovesdan.Sq [[:<:]]
337*4dc88ebeSGabor Kovesdanand
338*4dc88ebeSGabor Kovesdan.Sq [[:>:]] ;
339*4dc88ebeSGabor Kovesdansee
340*4dc88ebeSGabor Kovesdan.Xr re_format 7 ) .
341*4dc88ebeSGabor Kovesdan.It Fl x , Fl Fl line-regexp
342*4dc88ebeSGabor KovesdanOnly input lines selected against an entire fixed string or regular
343*4dc88ebeSGabor Kovesdanexpression are considered to be matching lines.
344*4dc88ebeSGabor Kovesdan.It Fl y
345*4dc88ebeSGabor KovesdanEquivalent to
346*4dc88ebeSGabor Kovesdan.Fl i .
347*4dc88ebeSGabor KovesdanObsoleted.
348*4dc88ebeSGabor Kovesdan.It Fl Z , Fl z , Fl Fl decompress
349*4dc88ebeSGabor KovesdanForce
350*4dc88ebeSGabor Kovesdan.Nm grep
351*4dc88ebeSGabor Kovesdanto behave as
352*4dc88ebeSGabor Kovesdan.Nm zgrep .
353*4dc88ebeSGabor Kovesdan.It Fl Fl binary-files Ns = Ns Ar value
354*4dc88ebeSGabor KovesdanControls searching and printing of binary files.
355*4dc88ebeSGabor KovesdanOptions are
356*4dc88ebeSGabor Kovesdan.Ar binary ,
357*4dc88ebeSGabor Kovesdanthe default: search binary files but do not print them;
358*4dc88ebeSGabor Kovesdan.Ar without-match :
359*4dc88ebeSGabor Kovesdando not search binary files;
360*4dc88ebeSGabor Kovesdanand
361*4dc88ebeSGabor Kovesdan.Ar text :
362*4dc88ebeSGabor Kovesdantreat all files as text.
363*4dc88ebeSGabor Kovesdan.Sm off
364*4dc88ebeSGabor Kovesdan.It Fl Fl context Op = Ar num
365*4dc88ebeSGabor Kovesdan.Sm on
366*4dc88ebeSGabor KovesdanPrint
367*4dc88ebeSGabor Kovesdan.Ar num
368*4dc88ebeSGabor Kovesdanlines of leading and trailing context.
369*4dc88ebeSGabor KovesdanThe default is 2.
370*4dc88ebeSGabor Kovesdan.It Fl Fl line-buffered
371*4dc88ebeSGabor KovesdanForce output to be line buffered.
372*4dc88ebeSGabor KovesdanBy default, output is line buffered when standard output is a terminal
373*4dc88ebeSGabor Kovesdanand block buffered otherwise.
374*4dc88ebeSGabor Kovesdan.Pp
375*4dc88ebeSGabor Kovesdan.El
376*4dc88ebeSGabor KovesdanIf no file arguments are specified, the standard input is used.
377*4dc88ebeSGabor Kovesdan.Sh RETURN VALUES
378*4dc88ebeSGabor KovesdanThe
379*4dc88ebeSGabor Kovesdan.Nm grep
380*4dc88ebeSGabor Kovesdanutility exits with one of the following values:
381*4dc88ebeSGabor Kovesdan.Pp
382*4dc88ebeSGabor Kovesdan.Bl -tag -width flag -compact
383*4dc88ebeSGabor Kovesdan.It Li 0
384*4dc88ebeSGabor KovesdanOne or more lines were selected.
385*4dc88ebeSGabor Kovesdan.It Li 1
386*4dc88ebeSGabor KovesdanNo lines were selected.
387*4dc88ebeSGabor Kovesdan.It Li \*(Gt1
388*4dc88ebeSGabor KovesdanAn error occurred.
389*4dc88ebeSGabor Kovesdan.El
390*4dc88ebeSGabor Kovesdan.Sh EXAMPLES
391*4dc88ebeSGabor KovesdanTo find all occurrences of the word
392*4dc88ebeSGabor Kovesdan.Sq patricia
393*4dc88ebeSGabor Kovesdanin a file:
394*4dc88ebeSGabor Kovesdan.Pp
395*4dc88ebeSGabor Kovesdan.Dl $ grep 'patricia' myfile
396*4dc88ebeSGabor Kovesdan.Pp
397*4dc88ebeSGabor KovesdanTo find all occurrences of the pattern
398*4dc88ebeSGabor Kovesdan.Ql .Pp
399*4dc88ebeSGabor Kovesdanat the beginning of a line:
400*4dc88ebeSGabor Kovesdan.Pp
401*4dc88ebeSGabor Kovesdan.Dl $ grep '^\e.Pp' myfile
402*4dc88ebeSGabor Kovesdan.Pp
403*4dc88ebeSGabor KovesdanThe apostrophes ensure the entire expression is evaluated by
404*4dc88ebeSGabor Kovesdan.Nm grep
405*4dc88ebeSGabor Kovesdaninstead of by the user's shell.
406*4dc88ebeSGabor KovesdanThe caret
407*4dc88ebeSGabor Kovesdan.Ql ^
408*4dc88ebeSGabor Kovesdanmatches the null string at the beginning of a line,
409*4dc88ebeSGabor Kovesdanand the
410*4dc88ebeSGabor Kovesdan.Ql \e
411*4dc88ebeSGabor Kovesdanescapes the
412*4dc88ebeSGabor Kovesdan.Ql \&. ,
413*4dc88ebeSGabor Kovesdanwhich would otherwise match any character.
414*4dc88ebeSGabor Kovesdan.Pp
415*4dc88ebeSGabor KovesdanTo find all lines in a file which do not contain the words
416*4dc88ebeSGabor Kovesdan.Sq foo
417*4dc88ebeSGabor Kovesdanor
418*4dc88ebeSGabor Kovesdan.Sq bar :
419*4dc88ebeSGabor Kovesdan.Pp
420*4dc88ebeSGabor Kovesdan.Dl $ grep -v -e 'foo' -e 'bar' myfile
421*4dc88ebeSGabor Kovesdan.Pp
422*4dc88ebeSGabor KovesdanA simple example of an extended regular expression:
423*4dc88ebeSGabor Kovesdan.Pp
424*4dc88ebeSGabor Kovesdan.Dl $ egrep '19|20|25' calendar
425*4dc88ebeSGabor Kovesdan.Pp
426*4dc88ebeSGabor KovesdanPeruses the file
427*4dc88ebeSGabor Kovesdan.Sq calendar
428*4dc88ebeSGabor Kovesdanlooking for either 19, 20, or 25.
429*4dc88ebeSGabor Kovesdan.Sh SEE ALSO
430*4dc88ebeSGabor Kovesdan.Xr ed 1 ,
431*4dc88ebeSGabor Kovesdan.Xr ex 1 ,
432*4dc88ebeSGabor Kovesdan.Xr gzip 1 ,
433*4dc88ebeSGabor Kovesdan.Xr sed 1 ,
434*4dc88ebeSGabor Kovesdan.Xr re_format 7
435*4dc88ebeSGabor Kovesdan.Sh STANDARDS
436*4dc88ebeSGabor KovesdanThe
437*4dc88ebeSGabor Kovesdan.Nm
438*4dc88ebeSGabor Kovesdanutility is compliant with the
439*4dc88ebeSGabor Kovesdan.St -p1003.1-2008
440*4dc88ebeSGabor Kovesdanspecification.
441*4dc88ebeSGabor Kovesdan.Pp
442*4dc88ebeSGabor KovesdanThe flags
443*4dc88ebeSGabor Kovesdan.Op Fl AaBbCDdGHhIJLmoPRSUVwZ
444*4dc88ebeSGabor Kovesdanare extensions to that specification, and the behaviour of the
445*4dc88ebeSGabor Kovesdan.Fl f
446*4dc88ebeSGabor Kovesdanflag when used with an empty pattern file is left undefined.
447*4dc88ebeSGabor Kovesdan.Pp
448*4dc88ebeSGabor KovesdanAll long options are provided for compatibility with
449*4dc88ebeSGabor KovesdanGNU versions of this utility.
450*4dc88ebeSGabor Kovesdan.Pp
451*4dc88ebeSGabor KovesdanHistoric versions of the
452*4dc88ebeSGabor Kovesdan.Nm grep
453*4dc88ebeSGabor Kovesdanutility also supported the flags
454*4dc88ebeSGabor Kovesdan.Op Fl ruy .
455*4dc88ebeSGabor KovesdanThis implementation supports those options;
456*4dc88ebeSGabor Kovesdanhowever, their use is strongly discouraged.
457*4dc88ebeSGabor Kovesdan.Sh HISTORY
458*4dc88ebeSGabor KovesdanThe
459*4dc88ebeSGabor Kovesdan.Nm grep
460*4dc88ebeSGabor Kovesdancommand first appeared in
461*4dc88ebeSGabor Kovesdan.At v6 .
462