xref: /freebsd/usr.bin/grep/grep.1 (revision bd509bdb851a789b442c730964f3a11ac160d5bc)
1b66a823bSGabor Kovesdan.\"	$NetBSD: grep.1,v 1.2 2011/02/16 01:31:33 joerg Exp $
24dc88ebeSGabor Kovesdan.\"	$FreeBSD$
34dc88ebeSGabor Kovesdan.\"	$OpenBSD: grep.1,v 1.38 2010/04/05 06:30:59 jmc Exp $
44dc88ebeSGabor Kovesdan.\" Copyright (c) 1980, 1990, 1993
54dc88ebeSGabor Kovesdan.\"	The Regents of the University of California.  All rights reserved.
64dc88ebeSGabor Kovesdan.\"
74dc88ebeSGabor Kovesdan.\" Redistribution and use in source and binary forms, with or without
84dc88ebeSGabor Kovesdan.\" modification, are permitted provided that the following conditions
94dc88ebeSGabor Kovesdan.\" are met:
104dc88ebeSGabor Kovesdan.\" 1. Redistributions of source code must retain the above copyright
114dc88ebeSGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer.
124dc88ebeSGabor Kovesdan.\" 2. Redistributions in binary form must reproduce the above copyright
134dc88ebeSGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer in the
144dc88ebeSGabor Kovesdan.\"    documentation and/or other materials provided with the distribution.
154dc88ebeSGabor Kovesdan.\" 3. Neither the name of the University nor the names of its contributors
164dc88ebeSGabor Kovesdan.\"    may be used to endorse or promote products derived from this software
174dc88ebeSGabor Kovesdan.\"    without specific prior written permission.
184dc88ebeSGabor Kovesdan.\"
194dc88ebeSGabor Kovesdan.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
204dc88ebeSGabor Kovesdan.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
214dc88ebeSGabor Kovesdan.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
224dc88ebeSGabor Kovesdan.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
234dc88ebeSGabor Kovesdan.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
244dc88ebeSGabor Kovesdan.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
254dc88ebeSGabor Kovesdan.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
264dc88ebeSGabor Kovesdan.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
274dc88ebeSGabor Kovesdan.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
284dc88ebeSGabor Kovesdan.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
294dc88ebeSGabor Kovesdan.\" SUCH DAMAGE.
304dc88ebeSGabor Kovesdan.\"
314dc88ebeSGabor Kovesdan.\"	@(#)grep.1	8.3 (Berkeley) 4/18/94
324dc88ebeSGabor Kovesdan.\"
334a5b4207SBaptiste Daroussin.Dd April 25, 2018
344dc88ebeSGabor Kovesdan.Dt GREP 1
354dc88ebeSGabor Kovesdan.Os
364dc88ebeSGabor Kovesdan.Sh NAME
37bf10f246SConrad Meyer.Nm grep , egrep , fgrep , rgrep ,
384dc88ebeSGabor Kovesdan.Nd file pattern searcher
394dc88ebeSGabor Kovesdan.Sh SYNOPSIS
404dc88ebeSGabor Kovesdan.Nm grep
414dc88ebeSGabor Kovesdan.Bk -words
424a5b4207SBaptiste Daroussin.Op Fl abcdDEFGHhIiLlmnOopqRSsUVvwxz
434dc88ebeSGabor Kovesdan.Op Fl A Ar num
444dc88ebeSGabor Kovesdan.Op Fl B Ar num
454dc88ebeSGabor Kovesdan.Op Fl C Ns Op Ar num
464dc88ebeSGabor Kovesdan.Op Fl e Ar pattern
474dc88ebeSGabor Kovesdan.Op Fl f Ar file
484dc88ebeSGabor Kovesdan.Op Fl Fl binary-files Ns = Ns Ar value
494dc88ebeSGabor Kovesdan.Op Fl Fl color Ns Op = Ns Ar when
504dc88ebeSGabor Kovesdan.Op Fl Fl colour Ns Op = Ns Ar when
514dc88ebeSGabor Kovesdan.Op Fl Fl context Ns Op = Ns Ar num
524dc88ebeSGabor Kovesdan.Op Fl Fl label
534dc88ebeSGabor Kovesdan.Op Fl Fl line-buffered
544dc88ebeSGabor Kovesdan.Op Fl Fl null
554dc88ebeSGabor Kovesdan.Op Ar pattern
564dc88ebeSGabor Kovesdan.Op Ar
574dc88ebeSGabor Kovesdan.Ek
584dc88ebeSGabor Kovesdan.Sh DESCRIPTION
594dc88ebeSGabor KovesdanThe
604dc88ebeSGabor Kovesdan.Nm grep
614dc88ebeSGabor Kovesdanutility searches any given input files,
624dc88ebeSGabor Kovesdanselecting lines that match one or more patterns.
634dc88ebeSGabor KovesdanBy default, a pattern matches an input line if the regular expression
644dc88ebeSGabor Kovesdan(RE) in the pattern matches the input line
654dc88ebeSGabor Kovesdanwithout its trailing newline.
664dc88ebeSGabor KovesdanAn empty expression matches every line.
674dc88ebeSGabor KovesdanEach input line that matches at least one of the patterns is written
684dc88ebeSGabor Kovesdanto the standard output.
694dc88ebeSGabor Kovesdan.Pp
704dc88ebeSGabor Kovesdan.Nm grep
714dc88ebeSGabor Kovesdanis used for simple patterns and
724dc88ebeSGabor Kovesdanbasic regular expressions
734dc88ebeSGabor Kovesdan.Pq BREs ;
744dc88ebeSGabor Kovesdan.Nm egrep
754dc88ebeSGabor Kovesdancan handle extended regular expressions
764dc88ebeSGabor Kovesdan.Pq EREs .
774dc88ebeSGabor KovesdanSee
784dc88ebeSGabor Kovesdan.Xr re_format 7
794dc88ebeSGabor Kovesdanfor more information on regular expressions.
804dc88ebeSGabor Kovesdan.Nm fgrep
814dc88ebeSGabor Kovesdanis quicker than both
824dc88ebeSGabor Kovesdan.Nm grep
834dc88ebeSGabor Kovesdanand
844dc88ebeSGabor Kovesdan.Nm egrep ,
854dc88ebeSGabor Kovesdanbut can only handle fixed patterns
864dc88ebeSGabor Kovesdan(i.e. it does not interpret regular expressions).
874dc88ebeSGabor KovesdanPatterns may consist of one or more lines,
884dc88ebeSGabor Kovesdanallowing any of the pattern lines to match a portion of the input.
894dc88ebeSGabor Kovesdan.Pp
904dc88ebeSGabor KovesdanThe following options are available:
914dc88ebeSGabor Kovesdan.Bl -tag -width indent
924dc88ebeSGabor Kovesdan.It Fl A Ar num , Fl Fl after-context Ns = Ns Ar num
934dc88ebeSGabor KovesdanPrint
944dc88ebeSGabor Kovesdan.Ar num
954dc88ebeSGabor Kovesdanlines of trailing context after each match.
964dc88ebeSGabor KovesdanSee also the
974dc88ebeSGabor Kovesdan.Fl B
984dc88ebeSGabor Kovesdanand
994dc88ebeSGabor Kovesdan.Fl C
1004dc88ebeSGabor Kovesdanoptions.
1014dc88ebeSGabor Kovesdan.It Fl a , Fl Fl text
1024dc88ebeSGabor KovesdanTreat all files as ASCII text.
1034dc88ebeSGabor KovesdanNormally
1044dc88ebeSGabor Kovesdan.Nm
1054dc88ebeSGabor Kovesdanwill simply print
1064dc88ebeSGabor Kovesdan.Dq Binary file ... matches
1074dc88ebeSGabor Kovesdanif files contain binary characters.
1084dc88ebeSGabor KovesdanUse of this option forces
1094dc88ebeSGabor Kovesdan.Nm
1104dc88ebeSGabor Kovesdanto output lines matching the specified pattern.
1114dc88ebeSGabor Kovesdan.It Fl B Ar num , Fl Fl before-context Ns = Ns Ar num
1124dc88ebeSGabor KovesdanPrint
1134dc88ebeSGabor Kovesdan.Ar num
1144dc88ebeSGabor Kovesdanlines of leading context before each match.
1154dc88ebeSGabor KovesdanSee also the
1164dc88ebeSGabor Kovesdan.Fl A
1174dc88ebeSGabor Kovesdanand
1184dc88ebeSGabor Kovesdan.Fl C
1194dc88ebeSGabor Kovesdanoptions.
1204dc88ebeSGabor Kovesdan.It Fl b , Fl Fl byte-offset
1214dc88ebeSGabor KovesdanThe offset in bytes of a matched pattern is
1224dc88ebeSGabor Kovesdandisplayed in front of the respective matched line.
1234dc88ebeSGabor Kovesdan.It Fl C Ns Op Ar num , Fl Fl context Ns = Ns Ar num
1244dc88ebeSGabor KovesdanPrint
1254dc88ebeSGabor Kovesdan.Ar num
1264dc88ebeSGabor Kovesdanlines of leading and trailing context surrounding each match.
1274dc88ebeSGabor KovesdanThe default is 2 and is equivalent to
1284dc88ebeSGabor Kovesdan.Fl A
1294dc88ebeSGabor Kovesdan.Ar 2
1304dc88ebeSGabor Kovesdan.Fl B
1314dc88ebeSGabor Kovesdan.Ar 2 .
1324dc88ebeSGabor KovesdanNote:
1334dc88ebeSGabor Kovesdanno whitespace may be given between the option and its argument.
1344dc88ebeSGabor Kovesdan.It Fl c , Fl Fl count
1354dc88ebeSGabor KovesdanOnly a count of selected lines is written to standard output.
1364dc88ebeSGabor Kovesdan.It Fl Fl colour Ns = Ns Op Ar when , Fl Fl color Ns = Ns Op Ar when
1374dc88ebeSGabor KovesdanMark up the matching text with the expression stored in
1384dc88ebeSGabor Kovesdan.Ev GREP_COLOR
1394dc88ebeSGabor Kovesdanenvironment variable.
1404dc88ebeSGabor KovesdanThe possible values of when can be `never', `always' or `auto'.
1414dc88ebeSGabor Kovesdan.It Fl D Ar action , Fl Fl devices Ns = Ns Ar action
1424dc88ebeSGabor KovesdanSpecify the demanded action for devices, FIFOs and sockets.
1434dc88ebeSGabor KovesdanThe default action is `read', which means, that they are read
1444dc88ebeSGabor Kovesdanas if they were normal files.
1454dc88ebeSGabor KovesdanIf the action is set to `skip', devices will be silently skipped.
1464dc88ebeSGabor Kovesdan.It Fl d Ar action , Fl Fl directories Ns = Ns Ar action
1474dc88ebeSGabor KovesdanSpecify the demanded action for directories.
1484dc88ebeSGabor KovesdanIt is `read' by default, which means that the directories
1494dc88ebeSGabor Kovesdanare read in the same manner as normal files.
1504dc88ebeSGabor KovesdanOther possible values are `skip' to silently ignore the
1514dc88ebeSGabor Kovesdandirectories, and `recurse' to read them recursively, which
1524dc88ebeSGabor Kovesdanhas the same effect as the
1534dc88ebeSGabor Kovesdan.Fl R
1544dc88ebeSGabor Kovesdanand
1554dc88ebeSGabor Kovesdan.Fl r
1564dc88ebeSGabor Kovesdanoption.
1574dc88ebeSGabor Kovesdan.It Fl E , Fl Fl extended-regexp
1584dc88ebeSGabor KovesdanInterpret
1594dc88ebeSGabor Kovesdan.Ar pattern
1604dc88ebeSGabor Kovesdanas an extended regular expression
1614dc88ebeSGabor Kovesdan(i.e. force
1624dc88ebeSGabor Kovesdan.Nm grep
1634dc88ebeSGabor Kovesdanto behave as
1644dc88ebeSGabor Kovesdan.Nm egrep ) .
1654dc88ebeSGabor Kovesdan.It Fl e Ar pattern , Fl Fl regexp Ns = Ns Ar pattern
1664dc88ebeSGabor KovesdanSpecify a pattern used during the search of the input:
1674dc88ebeSGabor Kovesdanan input line is selected if it matches any of the specified patterns.
1684dc88ebeSGabor KovesdanThis option is most useful when multiple
1694dc88ebeSGabor Kovesdan.Fl e
1704dc88ebeSGabor Kovesdanoptions are used to specify multiple patterns,
1714dc88ebeSGabor Kovesdanor when a pattern begins with a dash
1724dc88ebeSGabor Kovesdan.Pq Sq - .
1734dc88ebeSGabor Kovesdan.It Fl Fl exclude
17455e44f51SGabor KovesdanIf specified, it excludes files matching the given
17555e44f51SGabor Kovesdanfilename pattern from the search.
17655e44f51SGabor KovesdanNote that
17755e44f51SGabor Kovesdan.Fl Fl exclude
178*bd509bdbSKyle Evansand
17955e44f51SGabor Kovesdan.Fl Fl include
180*bd509bdbSKyle Evanspatterns are processed in the order given.
181*bd509bdbSKyle EvansIf a name patches multiple patterns, the latest matching rule wins.
182*bd509bdbSKyle EvansIf no
18355e44f51SGabor Kovesdan.Fl Fl include
18455e44f51SGabor Kovesdanpattern is specified, all files are searched that are
18555e44f51SGabor Kovesdannot excluded.
18655e44f51SGabor KovesdanPatterns are matched to the full path specified,
18755e44f51SGabor Kovesdannot only to the filename component.
1884dc88ebeSGabor Kovesdan.It Fl Fl exclude-dir
1894dc88ebeSGabor KovesdanIf
1904dc88ebeSGabor Kovesdan.Fl R
1914dc88ebeSGabor Kovesdanis specified, it excludes directories matching the
19255e44f51SGabor Kovesdangiven filename pattern from the search.
19355e44f51SGabor KovesdanNote that
19455e44f51SGabor Kovesdan.Fl Fl exclude-dir
195*bd509bdbSKyle Evansand
19655e44f51SGabor Kovesdan.Fl Fl include-dir
197*bd509bdbSKyle Evanspatterns are processed in the order given.
198*bd509bdbSKyle EvansIf a name patches multiple patterns, the latest matching rule wins.
199*bd509bdbSKyle EvansIf no
20055e44f51SGabor Kovesdan.Fl Fl include-dir
20155e44f51SGabor Kovesdanpattern is specified, all directories are searched that are
20255e44f51SGabor Kovesdannot excluded.
2034dc88ebeSGabor Kovesdan.It Fl F , Fl Fl fixed-strings
2044dc88ebeSGabor KovesdanInterpret
2054dc88ebeSGabor Kovesdan.Ar pattern
2064dc88ebeSGabor Kovesdanas a set of fixed strings
2074dc88ebeSGabor Kovesdan(i.e. force
2084dc88ebeSGabor Kovesdan.Nm grep
2094dc88ebeSGabor Kovesdanto behave as
2104dc88ebeSGabor Kovesdan.Nm fgrep ) .
2114dc88ebeSGabor Kovesdan.It Fl f Ar file , Fl Fl file Ns = Ns Ar file
2124dc88ebeSGabor KovesdanRead one or more newline separated patterns from
2134dc88ebeSGabor Kovesdan.Ar file .
2144dc88ebeSGabor KovesdanEmpty pattern lines match every input line.
2154dc88ebeSGabor KovesdanNewlines are not considered part of a pattern.
2164dc88ebeSGabor KovesdanIf
2174dc88ebeSGabor Kovesdan.Ar file
2184dc88ebeSGabor Kovesdanis empty, nothing is matched.
2194dc88ebeSGabor Kovesdan.It Fl G , Fl Fl basic-regexp
2204dc88ebeSGabor KovesdanInterpret
2214dc88ebeSGabor Kovesdan.Ar pattern
2224dc88ebeSGabor Kovesdanas a basic regular expression
2234dc88ebeSGabor Kovesdan(i.e. force
2244dc88ebeSGabor Kovesdan.Nm grep
2254dc88ebeSGabor Kovesdanto behave as traditional
2264dc88ebeSGabor Kovesdan.Nm grep ) .
2274dc88ebeSGabor Kovesdan.It Fl H
2284dc88ebeSGabor KovesdanAlways print filename headers with output lines.
2294dc88ebeSGabor Kovesdan.It Fl h , Fl Fl no-filename
2304dc88ebeSGabor KovesdanNever print filename headers
2314dc88ebeSGabor Kovesdan.Pq i.e. filenames
2324dc88ebeSGabor Kovesdanwith output lines.
2334dc88ebeSGabor Kovesdan.It Fl Fl help
2344dc88ebeSGabor KovesdanPrint a brief help message.
2354dc88ebeSGabor Kovesdan.It Fl I
2364dc88ebeSGabor KovesdanIgnore binary files.
2374dc88ebeSGabor KovesdanThis option is equivalent to
2384dc88ebeSGabor Kovesdan.Fl Fl binary-file Ns = Ns Ar without-match
2394dc88ebeSGabor Kovesdanoption.
2404dc88ebeSGabor Kovesdan.It Fl i , Fl Fl ignore-case
2414dc88ebeSGabor KovesdanPerform case insensitive matching.
2424dc88ebeSGabor KovesdanBy default,
2434dc88ebeSGabor Kovesdan.Nm grep
2444dc88ebeSGabor Kovesdanis case sensitive.
2454dc88ebeSGabor Kovesdan.It Fl Fl include
24655e44f51SGabor KovesdanIf specified, only files matching the
24755e44f51SGabor Kovesdangiven filename pattern are searched.
24855e44f51SGabor KovesdanNote that
24955e44f51SGabor Kovesdan.Fl Fl include
250*bd509bdbSKyle Evansand
251*bd509bdbSKyle Evans.Fl Fl exclude
252*bd509bdbSKyle Evanspatterns are processed in the order given.
253*bd509bdbSKyle EvansIf a name patches multiple patterns, the latest matching rule wins.
25455e44f51SGabor KovesdanPatterns are matched to the full path specified,
25555e44f51SGabor Kovesdannot only to the filename component.
2564dc88ebeSGabor Kovesdan.It Fl Fl include-dir
2574dc88ebeSGabor KovesdanIf
2584dc88ebeSGabor Kovesdan.Fl R
25955e44f51SGabor Kovesdanis specified, only directories matching the
26055e44f51SGabor Kovesdangiven filename pattern are searched.
26155e44f51SGabor KovesdanNote that
26255e44f51SGabor Kovesdan.Fl Fl include-dir
263*bd509bdbSKyle Evansand
264*bd509bdbSKyle Evans.Fl Fl exclude-dir
265*bd509bdbSKyle Evanspatterns are processed in the order given.
266*bd509bdbSKyle EvansIf a name patches multiple patterns, the latest matching rule wins.
2674dc88ebeSGabor Kovesdan.It Fl L , Fl Fl files-without-match
2684dc88ebeSGabor KovesdanOnly the names of files not containing selected lines are written to
2694dc88ebeSGabor Kovesdanstandard output.
2704dc88ebeSGabor KovesdanPathnames are listed once per file searched.
2714dc88ebeSGabor KovesdanIf the standard input is searched, the string
2724dc88ebeSGabor Kovesdan.Dq (standard input)
273*bd509bdbSKyle Evansis written unless a
274*bd509bdbSKyle Evans.Fl Fl label
275*bd509bdbSKyle Evansis specified.
2764dc88ebeSGabor Kovesdan.It Fl l , Fl Fl files-with-matches
2774dc88ebeSGabor KovesdanOnly the names of files containing selected lines are written to
2784dc88ebeSGabor Kovesdanstandard output.
2794dc88ebeSGabor Kovesdan.Nm grep
2804dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
2814dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
2824dc88ebeSGabor KovesdanPathnames are listed once per file searched.
2834dc88ebeSGabor KovesdanIf the standard input is searched, the string
2844dc88ebeSGabor Kovesdan.Dq (standard input)
285*bd509bdbSKyle Evansis written unless a
286*bd509bdbSKyle Evans.Fl Fl label
287*bd509bdbSKyle Evansis specified.
288*bd509bdbSKyle Evans.It Fl Fl label
289*bd509bdbSKyle EvansLabel to use in place of
290*bd509bdbSKyle Evans.Dq (standard input)
291*bd509bdbSKyle Evansfor a file name where a file name would normally be printed.
292*bd509bdbSKyle EvansThis option applies to
293*bd509bdbSKyle Evans.Fl H ,
294*bd509bdbSKyle Evans.Fl L ,
295*bd509bdbSKyle Evansand
296*bd509bdbSKyle Evans.Fl l .
2974dc88ebeSGabor Kovesdan.It Fl Fl mmap
2984dc88ebeSGabor KovesdanUse
2994dc88ebeSGabor Kovesdan.Xr mmap 2
3004dc88ebeSGabor Kovesdaninstead of
3014dc88ebeSGabor Kovesdan.Xr read 2
3024dc88ebeSGabor Kovesdanto read input, which can result in better performance under some
303a4f5b3dfSJoel Dahlcircumstances but can cause undefined behaviour.
3044dc88ebeSGabor Kovesdan.It Fl m Ar num, Fl Fl max-count Ns = Ns Ar num
3054dc88ebeSGabor KovesdanStop reading the file after
3064dc88ebeSGabor Kovesdan.Ar num
3074dc88ebeSGabor Kovesdanmatches.
3084dc88ebeSGabor Kovesdan.It Fl n , Fl Fl line-number
3094dc88ebeSGabor KovesdanEach output line is preceded by its relative line number in the file,
3104dc88ebeSGabor Kovesdanstarting at line 1.
3114dc88ebeSGabor KovesdanThe line number counter is reset for each file processed.
3124dc88ebeSGabor KovesdanThis option is ignored if
3134dc88ebeSGabor Kovesdan.Fl c ,
3144dc88ebeSGabor Kovesdan.Fl L ,
3154dc88ebeSGabor Kovesdan.Fl l ,
3164dc88ebeSGabor Kovesdanor
3174dc88ebeSGabor Kovesdan.Fl q
3184dc88ebeSGabor Kovesdanis
3194dc88ebeSGabor Kovesdanspecified.
3204dc88ebeSGabor Kovesdan.It Fl Fl null
3214dc88ebeSGabor KovesdanPrints a zero-byte after the file name.
3224dc88ebeSGabor Kovesdan.It Fl O
3234dc88ebeSGabor KovesdanIf
3244dc88ebeSGabor Kovesdan.Fl R
3254dc88ebeSGabor Kovesdanis specified, follow symbolic links only if they were explicitly listed
3264dc88ebeSGabor Kovesdanon the command line.
3274dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
3284dc88ebeSGabor Kovesdan.It Fl o, Fl Fl only-matching
3294dc88ebeSGabor KovesdanPrints only the matching part of the lines.
3304dc88ebeSGabor Kovesdan.It Fl p
3314dc88ebeSGabor KovesdanIf
3324dc88ebeSGabor Kovesdan.Fl R
3334dc88ebeSGabor Kovesdanis specified, no symbolic links are followed.
3344dc88ebeSGabor KovesdanThis is the default.
3354dc88ebeSGabor Kovesdan.It Fl q , Fl Fl quiet , Fl Fl silent
3364dc88ebeSGabor KovesdanQuiet mode:
3374dc88ebeSGabor Kovesdansuppress normal output.
3384dc88ebeSGabor Kovesdan.Nm grep
3394dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
3404dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
3414dc88ebeSGabor Kovesdan.It Fl R , Fl r , Fl Fl recursive
3424dc88ebeSGabor KovesdanRecursively search subdirectories listed.
343bf10f246SConrad Meyer(i.e. force
344bf10f246SConrad Meyer.Nm grep
345bf10f246SConrad Meyerto behave as
346bf10f246SConrad Meyer.Nm rgrep ) .
3474dc88ebeSGabor Kovesdan.It Fl S
3484dc88ebeSGabor KovesdanIf
3494dc88ebeSGabor Kovesdan.Fl R
3504dc88ebeSGabor Kovesdanis specified, all symbolic links are followed.
3514dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
3524dc88ebeSGabor Kovesdan.It Fl s , Fl Fl no-messages
3534dc88ebeSGabor KovesdanSilent mode.
3544dc88ebeSGabor KovesdanNonexistent and unreadable files are ignored
3554dc88ebeSGabor Kovesdan(i.e. their error messages are suppressed).
3564dc88ebeSGabor Kovesdan.It Fl U , Fl Fl binary
3574dc88ebeSGabor KovesdanSearch binary files, but do not attempt to print them.
3586b91f517SEd Maste.It Fl u
3596b91f517SEd MasteThis option has no effect and is provided only for compatibility with GNU grep.
3604dc88ebeSGabor Kovesdan.It Fl V , Fl Fl version
3614dc88ebeSGabor KovesdanDisplay version information and exit.
3624dc88ebeSGabor Kovesdan.It Fl v , Fl Fl invert-match
3634dc88ebeSGabor KovesdanSelected lines are those
3644dc88ebeSGabor Kovesdan.Em not
3654dc88ebeSGabor Kovesdanmatching any of the specified patterns.
3664dc88ebeSGabor Kovesdan.It Fl w , Fl Fl word-regexp
3674dc88ebeSGabor KovesdanThe expression is searched for as a word (as if surrounded by
3684dc88ebeSGabor Kovesdan.Sq [[:<:]]
3694dc88ebeSGabor Kovesdanand
3704dc88ebeSGabor Kovesdan.Sq [[:>:]] ;
3714dc88ebeSGabor Kovesdansee
3724dc88ebeSGabor Kovesdan.Xr re_format 7 ) .
3734dc88ebeSGabor Kovesdan.It Fl x , Fl Fl line-regexp
3744dc88ebeSGabor KovesdanOnly input lines selected against an entire fixed string or regular
3754dc88ebeSGabor Kovesdanexpression are considered to be matching lines.
3764dc88ebeSGabor Kovesdan.It Fl y
3774dc88ebeSGabor KovesdanEquivalent to
3784dc88ebeSGabor Kovesdan.Fl i .
3794dc88ebeSGabor KovesdanObsoleted.
3805ee1ea02SEd Maste.It Fl z , Fl Fl null-data
3815ee1ea02SEd MasteTreat input and output data as sequences of lines terminated by a
3825ee1ea02SEd Mastezero-byte instead of a newline.
3834dc88ebeSGabor Kovesdan.It Fl Fl binary-files Ns = Ns Ar value
3844dc88ebeSGabor KovesdanControls searching and printing of binary files.
3854dc88ebeSGabor KovesdanOptions are
3864dc88ebeSGabor Kovesdan.Ar binary ,
3874dc88ebeSGabor Kovesdanthe default: search binary files but do not print them;
3884dc88ebeSGabor Kovesdan.Ar without-match :
3894dc88ebeSGabor Kovesdando not search binary files;
3904dc88ebeSGabor Kovesdanand
3914dc88ebeSGabor Kovesdan.Ar text :
3924dc88ebeSGabor Kovesdantreat all files as text.
3934dc88ebeSGabor Kovesdan.Sm off
3944dc88ebeSGabor Kovesdan.It Fl Fl context Op = Ar num
3954dc88ebeSGabor Kovesdan.Sm on
3964dc88ebeSGabor KovesdanPrint
3974dc88ebeSGabor Kovesdan.Ar num
3984dc88ebeSGabor Kovesdanlines of leading and trailing context.
3994dc88ebeSGabor KovesdanThe default is 2.
4004dc88ebeSGabor Kovesdan.It Fl Fl line-buffered
4014dc88ebeSGabor KovesdanForce output to be line buffered.
4024dc88ebeSGabor KovesdanBy default, output is line buffered when standard output is a terminal
4034dc88ebeSGabor Kovesdanand block buffered otherwise.
4044dc88ebeSGabor Kovesdan.El
4057e700c30SJoel Dahl.Pp
4064dc88ebeSGabor KovesdanIf no file arguments are specified, the standard input is used.
407e9a67923SGabor Kovesdan.Sh EXIT STATUS
4084dc88ebeSGabor KovesdanThe
4094dc88ebeSGabor Kovesdan.Nm grep
4104dc88ebeSGabor Kovesdanutility exits with one of the following values:
4114dc88ebeSGabor Kovesdan.Pp
4124dc88ebeSGabor Kovesdan.Bl -tag -width flag -compact
4134dc88ebeSGabor Kovesdan.It Li 0
4144dc88ebeSGabor KovesdanOne or more lines were selected.
4154dc88ebeSGabor Kovesdan.It Li 1
4164dc88ebeSGabor KovesdanNo lines were selected.
4174dc88ebeSGabor Kovesdan.It Li \*(Gt1
4184dc88ebeSGabor KovesdanAn error occurred.
4194dc88ebeSGabor Kovesdan.El
4204dc88ebeSGabor Kovesdan.Sh EXAMPLES
4214dc88ebeSGabor KovesdanTo find all occurrences of the word
4224dc88ebeSGabor Kovesdan.Sq patricia
4234dc88ebeSGabor Kovesdanin a file:
4244dc88ebeSGabor Kovesdan.Pp
4254dc88ebeSGabor Kovesdan.Dl $ grep 'patricia' myfile
4264dc88ebeSGabor Kovesdan.Pp
4274dc88ebeSGabor KovesdanTo find all occurrences of the pattern
4284dc88ebeSGabor Kovesdan.Ql .Pp
4294dc88ebeSGabor Kovesdanat the beginning of a line:
4304dc88ebeSGabor Kovesdan.Pp
4314dc88ebeSGabor Kovesdan.Dl $ grep '^\e.Pp' myfile
4324dc88ebeSGabor Kovesdan.Pp
4334dc88ebeSGabor KovesdanThe apostrophes ensure the entire expression is evaluated by
4344dc88ebeSGabor Kovesdan.Nm grep
4354dc88ebeSGabor Kovesdaninstead of by the user's shell.
4364dc88ebeSGabor KovesdanThe caret
4374dc88ebeSGabor Kovesdan.Ql ^
4384dc88ebeSGabor Kovesdanmatches the null string at the beginning of a line,
4394dc88ebeSGabor Kovesdanand the
4404dc88ebeSGabor Kovesdan.Ql \e
4414dc88ebeSGabor Kovesdanescapes the
4424dc88ebeSGabor Kovesdan.Ql \&. ,
4434dc88ebeSGabor Kovesdanwhich would otherwise match any character.
4444dc88ebeSGabor Kovesdan.Pp
4454dc88ebeSGabor KovesdanTo find all lines in a file which do not contain the words
4464dc88ebeSGabor Kovesdan.Sq foo
4474dc88ebeSGabor Kovesdanor
4484dc88ebeSGabor Kovesdan.Sq bar :
4494dc88ebeSGabor Kovesdan.Pp
4504dc88ebeSGabor Kovesdan.Dl $ grep -v -e 'foo' -e 'bar' myfile
4514dc88ebeSGabor Kovesdan.Pp
4524dc88ebeSGabor KovesdanA simple example of an extended regular expression:
4534dc88ebeSGabor Kovesdan.Pp
4544dc88ebeSGabor Kovesdan.Dl $ egrep '19|20|25' calendar
4554dc88ebeSGabor Kovesdan.Pp
4564dc88ebeSGabor KovesdanPeruses the file
4574dc88ebeSGabor Kovesdan.Sq calendar
4584dc88ebeSGabor Kovesdanlooking for either 19, 20, or 25.
4594dc88ebeSGabor Kovesdan.Sh SEE ALSO
4604dc88ebeSGabor Kovesdan.Xr ed 1 ,
4614dc88ebeSGabor Kovesdan.Xr ex 1 ,
4624dc88ebeSGabor Kovesdan.Xr sed 1 ,
4634dc88ebeSGabor Kovesdan.Xr re_format 7
4644dc88ebeSGabor Kovesdan.Sh STANDARDS
4654dc88ebeSGabor KovesdanThe
4664dc88ebeSGabor Kovesdan.Nm
4674dc88ebeSGabor Kovesdanutility is compliant with the
4684dc88ebeSGabor Kovesdan.St -p1003.1-2008
4694dc88ebeSGabor Kovesdanspecification.
4704dc88ebeSGabor Kovesdan.Pp
4714dc88ebeSGabor KovesdanThe flags
472*bd509bdbSKyle Evans.Op Fl AaBbCDdGHhILmoPRSUVw
4734dc88ebeSGabor Kovesdanare extensions to that specification, and the behaviour of the
4744dc88ebeSGabor Kovesdan.Fl f
4754dc88ebeSGabor Kovesdanflag when used with an empty pattern file is left undefined.
4764dc88ebeSGabor Kovesdan.Pp
4774dc88ebeSGabor KovesdanAll long options are provided for compatibility with
4784dc88ebeSGabor KovesdanGNU versions of this utility.
4794dc88ebeSGabor Kovesdan.Pp
4804dc88ebeSGabor KovesdanHistoric versions of the
4814dc88ebeSGabor Kovesdan.Nm grep
4824dc88ebeSGabor Kovesdanutility also supported the flags
4834dc88ebeSGabor Kovesdan.Op Fl ruy .
4844dc88ebeSGabor KovesdanThis implementation supports those options;
4854dc88ebeSGabor Kovesdanhowever, their use is strongly discouraged.
4864dc88ebeSGabor Kovesdan.Sh HISTORY
4874dc88ebeSGabor KovesdanThe
4884dc88ebeSGabor Kovesdan.Nm grep
4894dc88ebeSGabor Kovesdancommand first appeared in
4904dc88ebeSGabor Kovesdan.At v6 .
491