xref: /freebsd/usr.bin/grep/grep.1 (revision 55e44f511ddc3d5684f5c06220101eba4166ff55)
14dc88ebeSGabor Kovesdan.\"	$FreeBSD$
24dc88ebeSGabor Kovesdan.\"	$OpenBSD: grep.1,v 1.38 2010/04/05 06:30:59 jmc Exp $
34dc88ebeSGabor Kovesdan.\" Copyright (c) 1980, 1990, 1993
44dc88ebeSGabor Kovesdan.\"	The Regents of the University of California.  All rights reserved.
54dc88ebeSGabor Kovesdan.\"
64dc88ebeSGabor Kovesdan.\" Redistribution and use in source and binary forms, with or without
74dc88ebeSGabor Kovesdan.\" modification, are permitted provided that the following conditions
84dc88ebeSGabor Kovesdan.\" are met:
94dc88ebeSGabor Kovesdan.\" 1. Redistributions of source code must retain the above copyright
104dc88ebeSGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer.
114dc88ebeSGabor Kovesdan.\" 2. Redistributions in binary form must reproduce the above copyright
124dc88ebeSGabor Kovesdan.\"    notice, this list of conditions and the following disclaimer in the
134dc88ebeSGabor Kovesdan.\"    documentation and/or other materials provided with the distribution.
144dc88ebeSGabor Kovesdan.\" 3. Neither the name of the University nor the names of its contributors
154dc88ebeSGabor Kovesdan.\"    may be used to endorse or promote products derived from this software
164dc88ebeSGabor Kovesdan.\"    without specific prior written permission.
174dc88ebeSGabor Kovesdan.\"
184dc88ebeSGabor Kovesdan.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
194dc88ebeSGabor Kovesdan.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
204dc88ebeSGabor Kovesdan.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
214dc88ebeSGabor Kovesdan.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
224dc88ebeSGabor Kovesdan.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
234dc88ebeSGabor Kovesdan.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
244dc88ebeSGabor Kovesdan.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
254dc88ebeSGabor Kovesdan.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
264dc88ebeSGabor Kovesdan.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
274dc88ebeSGabor Kovesdan.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
284dc88ebeSGabor Kovesdan.\" SUCH DAMAGE.
294dc88ebeSGabor Kovesdan.\"
304dc88ebeSGabor Kovesdan.\"	@(#)grep.1	8.3 (Berkeley) 4/18/94
314dc88ebeSGabor Kovesdan.\"
32*55e44f51SGabor Kovesdan.Dd July 28, 2010
334dc88ebeSGabor Kovesdan.Dt GREP 1
344dc88ebeSGabor Kovesdan.Os
354dc88ebeSGabor Kovesdan.Sh NAME
364dc88ebeSGabor Kovesdan.Nm grep , egrep , fgrep ,
374dc88ebeSGabor Kovesdan.Nm zgrep , zegrep , zfgrep
384dc88ebeSGabor Kovesdan.Nd file pattern searcher
394dc88ebeSGabor Kovesdan.Sh SYNOPSIS
404dc88ebeSGabor Kovesdan.Nm grep
414dc88ebeSGabor Kovesdan.Bk -words
424dc88ebeSGabor Kovesdan.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZ
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 Kovesdan.Nm zgrep ,
914dc88ebeSGabor Kovesdan.Nm zegrep ,
924dc88ebeSGabor Kovesdanand
934dc88ebeSGabor Kovesdan.Nm zfgrep
944dc88ebeSGabor Kovesdanact like
954dc88ebeSGabor Kovesdan.Nm grep ,
964dc88ebeSGabor Kovesdan.Nm egrep ,
974dc88ebeSGabor Kovesdanand
984dc88ebeSGabor Kovesdan.Nm fgrep ,
994dc88ebeSGabor Kovesdanrespectively, but accept input files compressed with the
1004dc88ebeSGabor Kovesdan.Xr compress 1
1014dc88ebeSGabor Kovesdanor
1024dc88ebeSGabor Kovesdan.Xr gzip 1
1034dc88ebeSGabor Kovesdancompression utilities.
1044dc88ebeSGabor Kovesdan.Pp
1054dc88ebeSGabor KovesdanThe following options are available:
1064dc88ebeSGabor Kovesdan.Bl -tag -width indent
1074dc88ebeSGabor Kovesdan.It Fl A Ar num , Fl Fl after-context Ns = Ns Ar num
1084dc88ebeSGabor KovesdanPrint
1094dc88ebeSGabor Kovesdan.Ar num
1104dc88ebeSGabor Kovesdanlines of trailing context after each match.
1114dc88ebeSGabor KovesdanSee also the
1124dc88ebeSGabor Kovesdan.Fl B
1134dc88ebeSGabor Kovesdanand
1144dc88ebeSGabor Kovesdan.Fl C
1154dc88ebeSGabor Kovesdanoptions.
1164dc88ebeSGabor Kovesdan.It Fl a , Fl Fl text
1174dc88ebeSGabor KovesdanTreat all files as ASCII text.
1184dc88ebeSGabor KovesdanNormally
1194dc88ebeSGabor Kovesdan.Nm
1204dc88ebeSGabor Kovesdanwill simply print
1214dc88ebeSGabor Kovesdan.Dq Binary file ... matches
1224dc88ebeSGabor Kovesdanif files contain binary characters.
1234dc88ebeSGabor KovesdanUse of this option forces
1244dc88ebeSGabor Kovesdan.Nm
1254dc88ebeSGabor Kovesdanto output lines matching the specified pattern.
1264dc88ebeSGabor Kovesdan.It Fl B Ar num , Fl Fl before-context Ns = Ns Ar num
1274dc88ebeSGabor KovesdanPrint
1284dc88ebeSGabor Kovesdan.Ar num
1294dc88ebeSGabor Kovesdanlines of leading context before each match.
1304dc88ebeSGabor KovesdanSee also the
1314dc88ebeSGabor Kovesdan.Fl A
1324dc88ebeSGabor Kovesdanand
1334dc88ebeSGabor Kovesdan.Fl C
1344dc88ebeSGabor Kovesdanoptions.
1354dc88ebeSGabor Kovesdan.It Fl b , Fl Fl byte-offset
1364dc88ebeSGabor KovesdanThe offset in bytes of a matched pattern is
1374dc88ebeSGabor Kovesdandisplayed in front of the respective matched line.
1384dc88ebeSGabor Kovesdan.It Fl C Ns Op Ar num , Fl Fl context Ns = Ns Ar num
1394dc88ebeSGabor KovesdanPrint
1404dc88ebeSGabor Kovesdan.Ar num
1414dc88ebeSGabor Kovesdanlines of leading and trailing context surrounding each match.
1424dc88ebeSGabor KovesdanThe default is 2 and is equivalent to
1434dc88ebeSGabor Kovesdan.Fl A
1444dc88ebeSGabor Kovesdan.Ar 2
1454dc88ebeSGabor Kovesdan.Fl B
1464dc88ebeSGabor Kovesdan.Ar 2 .
1474dc88ebeSGabor KovesdanNote:
1484dc88ebeSGabor Kovesdanno whitespace may be given between the option and its argument.
1494dc88ebeSGabor Kovesdan.It Fl c , Fl Fl count
1504dc88ebeSGabor KovesdanOnly a count of selected lines is written to standard output.
1514dc88ebeSGabor Kovesdan.It Fl Fl colour Ns = Ns Op Ar when , Fl Fl color Ns = Ns Op Ar when
1524dc88ebeSGabor KovesdanMark up the matching text with the expression stored in
1534dc88ebeSGabor Kovesdan.Ev GREP_COLOR
1544dc88ebeSGabor Kovesdanenvironment variable.
1554dc88ebeSGabor KovesdanThe possible values of when can be `never', `always' or `auto'.
1564dc88ebeSGabor Kovesdan.It Fl D Ar action , Fl Fl devices Ns = Ns Ar action
1574dc88ebeSGabor KovesdanSpecify the demanded action for devices, FIFOs and sockets.
1584dc88ebeSGabor KovesdanThe default action is `read', which means, that they are read
1594dc88ebeSGabor Kovesdanas if they were normal files.
1604dc88ebeSGabor KovesdanIf the action is set to `skip', devices will be silently skipped.
1614dc88ebeSGabor Kovesdan.It Fl d Ar action , Fl Fl directories Ns = Ns Ar action
1624dc88ebeSGabor KovesdanSpecify the demanded action for directories.
1634dc88ebeSGabor KovesdanIt is `read' by default, which means that the directories
1644dc88ebeSGabor Kovesdanare read in the same manner as normal files.
1654dc88ebeSGabor KovesdanOther possible values are `skip' to silently ignore the
1664dc88ebeSGabor Kovesdandirectories, and `recurse' to read them recursively, which
1674dc88ebeSGabor Kovesdanhas the same effect as the
1684dc88ebeSGabor Kovesdan.Fl R
1694dc88ebeSGabor Kovesdanand
1704dc88ebeSGabor Kovesdan.Fl r
1714dc88ebeSGabor Kovesdanoption.
1724dc88ebeSGabor Kovesdan.It Fl E , Fl Fl extended-regexp
1734dc88ebeSGabor KovesdanInterpret
1744dc88ebeSGabor Kovesdan.Ar pattern
1754dc88ebeSGabor Kovesdanas an extended regular expression
1764dc88ebeSGabor Kovesdan(i.e. force
1774dc88ebeSGabor Kovesdan.Nm grep
1784dc88ebeSGabor Kovesdanto behave as
1794dc88ebeSGabor Kovesdan.Nm egrep ) .
1804dc88ebeSGabor Kovesdan.It Fl e Ar pattern , Fl Fl regexp Ns = Ns Ar pattern
1814dc88ebeSGabor KovesdanSpecify a pattern used during the search of the input:
1824dc88ebeSGabor Kovesdanan input line is selected if it matches any of the specified patterns.
1834dc88ebeSGabor KovesdanThis option is most useful when multiple
1844dc88ebeSGabor Kovesdan.Fl e
1854dc88ebeSGabor Kovesdanoptions are used to specify multiple patterns,
1864dc88ebeSGabor Kovesdanor when a pattern begins with a dash
1874dc88ebeSGabor Kovesdan.Pq Sq - .
1884dc88ebeSGabor Kovesdan.It Fl Fl exclude
189*55e44f51SGabor KovesdanIf specified, it excludes files matching the given
190*55e44f51SGabor Kovesdanfilename pattern from the search.
191*55e44f51SGabor KovesdanNote that
192*55e44f51SGabor Kovesdan.Fl Fl exclude
193*55e44f51SGabor Kovesdanpatterns take priority over
194*55e44f51SGabor Kovesdan.Fl Fl include
195*55e44f51SGabor Kovesdanpatterns, and if no
196*55e44f51SGabor Kovesdan.Fl Fl include
197*55e44f51SGabor Kovesdanpattern is specified, all files are searched that are
198*55e44f51SGabor Kovesdannot excluded.
199*55e44f51SGabor KovesdanPatterns are matched to the full path specified,
200*55e44f51SGabor Kovesdannot only to the filename component.
2014dc88ebeSGabor Kovesdan.It Fl Fl exclude-dir
2024dc88ebeSGabor KovesdanIf
2034dc88ebeSGabor Kovesdan.Fl R
2044dc88ebeSGabor Kovesdanis specified, it excludes directories matching the
205*55e44f51SGabor Kovesdangiven filename pattern from the search.
206*55e44f51SGabor KovesdanNote that
207*55e44f51SGabor Kovesdan.Fl Fl exclude-dir
208*55e44f51SGabor Kovesdanpatterns take priority over
209*55e44f51SGabor Kovesdan.Fl Fl include-dir
210*55e44f51SGabor Kovesdanpatterns, and if no
211*55e44f51SGabor Kovesdan.Fl Fl include-dir
212*55e44f51SGabor Kovesdanpattern is specified, all directories are searched that are
213*55e44f51SGabor Kovesdannot excluded.
2144dc88ebeSGabor Kovesdan.It Fl F , Fl Fl fixed-strings
2154dc88ebeSGabor KovesdanInterpret
2164dc88ebeSGabor Kovesdan.Ar pattern
2174dc88ebeSGabor Kovesdanas a set of fixed strings
2184dc88ebeSGabor Kovesdan(i.e. force
2194dc88ebeSGabor Kovesdan.Nm grep
2204dc88ebeSGabor Kovesdanto behave as
2214dc88ebeSGabor Kovesdan.Nm fgrep ) .
2224dc88ebeSGabor Kovesdan.It Fl f Ar file , Fl Fl file Ns = Ns Ar file
2234dc88ebeSGabor KovesdanRead one or more newline separated patterns from
2244dc88ebeSGabor Kovesdan.Ar file .
2254dc88ebeSGabor KovesdanEmpty pattern lines match every input line.
2264dc88ebeSGabor KovesdanNewlines are not considered part of a pattern.
2274dc88ebeSGabor KovesdanIf
2284dc88ebeSGabor Kovesdan.Ar file
2294dc88ebeSGabor Kovesdanis empty, nothing is matched.
2304dc88ebeSGabor Kovesdan.It Fl G , Fl Fl basic-regexp
2314dc88ebeSGabor KovesdanInterpret
2324dc88ebeSGabor Kovesdan.Ar pattern
2334dc88ebeSGabor Kovesdanas a basic regular expression
2344dc88ebeSGabor Kovesdan(i.e. force
2354dc88ebeSGabor Kovesdan.Nm grep
2364dc88ebeSGabor Kovesdanto behave as traditional
2374dc88ebeSGabor Kovesdan.Nm grep ) .
2384dc88ebeSGabor Kovesdan.It Fl H
2394dc88ebeSGabor KovesdanAlways print filename headers with output lines.
2404dc88ebeSGabor Kovesdan.It Fl h , Fl Fl no-filename
2414dc88ebeSGabor KovesdanNever print filename headers
2424dc88ebeSGabor Kovesdan.Pq i.e. filenames
2434dc88ebeSGabor Kovesdanwith output lines.
2444dc88ebeSGabor Kovesdan.It Fl Fl help
2454dc88ebeSGabor KovesdanPrint a brief help message.
2464dc88ebeSGabor Kovesdan.It Fl I
2474dc88ebeSGabor KovesdanIgnore binary files.
2484dc88ebeSGabor KovesdanThis option is equivalent to
2494dc88ebeSGabor Kovesdan.Fl Fl binary-file Ns = Ns Ar without-match
2504dc88ebeSGabor Kovesdanoption.
2514dc88ebeSGabor Kovesdan.It Fl i , Fl Fl ignore-case
2524dc88ebeSGabor KovesdanPerform case insensitive matching.
2534dc88ebeSGabor KovesdanBy default,
2544dc88ebeSGabor Kovesdan.Nm grep
2554dc88ebeSGabor Kovesdanis case sensitive.
2564dc88ebeSGabor Kovesdan.It Fl Fl include
257*55e44f51SGabor KovesdanIf specified, only files matching the
258*55e44f51SGabor Kovesdangiven filename pattern are searched.
259*55e44f51SGabor KovesdanNote that
260*55e44f51SGabor Kovesdan.Fl Fl exclude
261*55e44f51SGabor Kovesdanpatterns take priority over
262*55e44f51SGabor Kovesdan.Fl Fl include
263*55e44f51SGabor Kovesdanpatterns.
264*55e44f51SGabor KovesdanPatterns are matched to the full path specified,
265*55e44f51SGabor Kovesdannot only to the filename component.
2664dc88ebeSGabor Kovesdan.It Fl Fl include-dir
2674dc88ebeSGabor KovesdanIf
2684dc88ebeSGabor Kovesdan.Fl R
269*55e44f51SGabor Kovesdanis specified, only directories matching the
270*55e44f51SGabor Kovesdangiven filename pattern are searched.
271*55e44f51SGabor KovesdanNote that
272*55e44f51SGabor Kovesdan.Fl Fl exclude-dir
273*55e44f51SGabor Kovesdanpatterns take priority over
274*55e44f51SGabor Kovesdan.Fl Fl include-dir
275*55e44f51SGabor Kovesdanpatterns.
2764dc88ebeSGabor Kovesdan.It Fl J, Fl Fl bz2decompress
2774dc88ebeSGabor KovesdanDecompress the
2784dc88ebeSGabor Kovesdan.Xr bzip2 1
2794dc88ebeSGabor Kovesdancompressed file before looking for the text.
2804dc88ebeSGabor Kovesdan.It Fl L , Fl Fl files-without-match
2814dc88ebeSGabor KovesdanOnly the names of files not containing selected lines are written to
2824dc88ebeSGabor Kovesdanstandard output.
2834dc88ebeSGabor KovesdanPathnames are listed once per file searched.
2844dc88ebeSGabor KovesdanIf the standard input is searched, the string
2854dc88ebeSGabor Kovesdan.Dq (standard input)
2864dc88ebeSGabor Kovesdanis written.
2874dc88ebeSGabor Kovesdan.It Fl l , Fl Fl files-with-matches
2884dc88ebeSGabor KovesdanOnly the names of files containing selected lines are written to
2894dc88ebeSGabor Kovesdanstandard output.
2904dc88ebeSGabor Kovesdan.Nm grep
2914dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
2924dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
2934dc88ebeSGabor KovesdanPathnames are listed once per file searched.
2944dc88ebeSGabor KovesdanIf the standard input is searched, the string
2954dc88ebeSGabor Kovesdan.Dq (standard input)
2964dc88ebeSGabor Kovesdanis written.
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
3034dc88ebeSGabor Kovesdancircumstances but can cause undefined behaiour.
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.
3434dc88ebeSGabor Kovesdan.It Fl S
3444dc88ebeSGabor KovesdanIf
3454dc88ebeSGabor Kovesdan.Fl R
3464dc88ebeSGabor Kovesdanis specified, all symbolic links are followed.
3474dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
3484dc88ebeSGabor Kovesdan.It Fl s , Fl Fl no-messages
3494dc88ebeSGabor KovesdanSilent mode.
3504dc88ebeSGabor KovesdanNonexistent and unreadable files are ignored
3514dc88ebeSGabor Kovesdan(i.e. their error messages are suppressed).
3524dc88ebeSGabor Kovesdan.It Fl U , Fl Fl binary
3534dc88ebeSGabor KovesdanSearch binary files, but do not attempt to print them.
3544dc88ebeSGabor Kovesdan.It Fl V , Fl Fl version
3554dc88ebeSGabor KovesdanDisplay version information and exit.
3564dc88ebeSGabor Kovesdan.It Fl v , Fl Fl invert-match
3574dc88ebeSGabor KovesdanSelected lines are those
3584dc88ebeSGabor Kovesdan.Em not
3594dc88ebeSGabor Kovesdanmatching any of the specified patterns.
3604dc88ebeSGabor Kovesdan.It Fl w , Fl Fl word-regexp
3614dc88ebeSGabor KovesdanThe expression is searched for as a word (as if surrounded by
3624dc88ebeSGabor Kovesdan.Sq [[:<:]]
3634dc88ebeSGabor Kovesdanand
3644dc88ebeSGabor Kovesdan.Sq [[:>:]] ;
3654dc88ebeSGabor Kovesdansee
3664dc88ebeSGabor Kovesdan.Xr re_format 7 ) .
3674dc88ebeSGabor Kovesdan.It Fl x , Fl Fl line-regexp
3684dc88ebeSGabor KovesdanOnly input lines selected against an entire fixed string or regular
3694dc88ebeSGabor Kovesdanexpression are considered to be matching lines.
3704dc88ebeSGabor Kovesdan.It Fl y
3714dc88ebeSGabor KovesdanEquivalent to
3724dc88ebeSGabor Kovesdan.Fl i .
3734dc88ebeSGabor KovesdanObsoleted.
3744dc88ebeSGabor Kovesdan.It Fl Z , Fl z , Fl Fl decompress
3754dc88ebeSGabor KovesdanForce
3764dc88ebeSGabor Kovesdan.Nm grep
3774dc88ebeSGabor Kovesdanto behave as
3784dc88ebeSGabor Kovesdan.Nm zgrep .
3794dc88ebeSGabor Kovesdan.It Fl Fl binary-files Ns = Ns Ar value
3804dc88ebeSGabor KovesdanControls searching and printing of binary files.
3814dc88ebeSGabor KovesdanOptions are
3824dc88ebeSGabor Kovesdan.Ar binary ,
3834dc88ebeSGabor Kovesdanthe default: search binary files but do not print them;
3844dc88ebeSGabor Kovesdan.Ar without-match :
3854dc88ebeSGabor Kovesdando not search binary files;
3864dc88ebeSGabor Kovesdanand
3874dc88ebeSGabor Kovesdan.Ar text :
3884dc88ebeSGabor Kovesdantreat all files as text.
3894dc88ebeSGabor Kovesdan.Sm off
3904dc88ebeSGabor Kovesdan.It Fl Fl context Op = Ar num
3914dc88ebeSGabor Kovesdan.Sm on
3924dc88ebeSGabor KovesdanPrint
3934dc88ebeSGabor Kovesdan.Ar num
3944dc88ebeSGabor Kovesdanlines of leading and trailing context.
3954dc88ebeSGabor KovesdanThe default is 2.
3964dc88ebeSGabor Kovesdan.It Fl Fl line-buffered
3974dc88ebeSGabor KovesdanForce output to be line buffered.
3984dc88ebeSGabor KovesdanBy default, output is line buffered when standard output is a terminal
3994dc88ebeSGabor Kovesdanand block buffered otherwise.
4004dc88ebeSGabor Kovesdan.Pp
4014dc88ebeSGabor Kovesdan.El
4024dc88ebeSGabor KovesdanIf no file arguments are specified, the standard input is used.
403e9a67923SGabor Kovesdan.Sh EXIT STATUS
4044dc88ebeSGabor KovesdanThe
4054dc88ebeSGabor Kovesdan.Nm grep
4064dc88ebeSGabor Kovesdanutility exits with one of the following values:
4074dc88ebeSGabor Kovesdan.Pp
4084dc88ebeSGabor Kovesdan.Bl -tag -width flag -compact
4094dc88ebeSGabor Kovesdan.It Li 0
4104dc88ebeSGabor KovesdanOne or more lines were selected.
4114dc88ebeSGabor Kovesdan.It Li 1
4124dc88ebeSGabor KovesdanNo lines were selected.
4134dc88ebeSGabor Kovesdan.It Li \*(Gt1
4144dc88ebeSGabor KovesdanAn error occurred.
4154dc88ebeSGabor Kovesdan.El
4164dc88ebeSGabor Kovesdan.Sh EXAMPLES
4174dc88ebeSGabor KovesdanTo find all occurrences of the word
4184dc88ebeSGabor Kovesdan.Sq patricia
4194dc88ebeSGabor Kovesdanin a file:
4204dc88ebeSGabor Kovesdan.Pp
4214dc88ebeSGabor Kovesdan.Dl $ grep 'patricia' myfile
4224dc88ebeSGabor Kovesdan.Pp
4234dc88ebeSGabor KovesdanTo find all occurrences of the pattern
4244dc88ebeSGabor Kovesdan.Ql .Pp
4254dc88ebeSGabor Kovesdanat the beginning of a line:
4264dc88ebeSGabor Kovesdan.Pp
4274dc88ebeSGabor Kovesdan.Dl $ grep '^\e.Pp' myfile
4284dc88ebeSGabor Kovesdan.Pp
4294dc88ebeSGabor KovesdanThe apostrophes ensure the entire expression is evaluated by
4304dc88ebeSGabor Kovesdan.Nm grep
4314dc88ebeSGabor Kovesdaninstead of by the user's shell.
4324dc88ebeSGabor KovesdanThe caret
4334dc88ebeSGabor Kovesdan.Ql ^
4344dc88ebeSGabor Kovesdanmatches the null string at the beginning of a line,
4354dc88ebeSGabor Kovesdanand the
4364dc88ebeSGabor Kovesdan.Ql \e
4374dc88ebeSGabor Kovesdanescapes the
4384dc88ebeSGabor Kovesdan.Ql \&. ,
4394dc88ebeSGabor Kovesdanwhich would otherwise match any character.
4404dc88ebeSGabor Kovesdan.Pp
4414dc88ebeSGabor KovesdanTo find all lines in a file which do not contain the words
4424dc88ebeSGabor Kovesdan.Sq foo
4434dc88ebeSGabor Kovesdanor
4444dc88ebeSGabor Kovesdan.Sq bar :
4454dc88ebeSGabor Kovesdan.Pp
4464dc88ebeSGabor Kovesdan.Dl $ grep -v -e 'foo' -e 'bar' myfile
4474dc88ebeSGabor Kovesdan.Pp
4484dc88ebeSGabor KovesdanA simple example of an extended regular expression:
4494dc88ebeSGabor Kovesdan.Pp
4504dc88ebeSGabor Kovesdan.Dl $ egrep '19|20|25' calendar
4514dc88ebeSGabor Kovesdan.Pp
4524dc88ebeSGabor KovesdanPeruses the file
4534dc88ebeSGabor Kovesdan.Sq calendar
4544dc88ebeSGabor Kovesdanlooking for either 19, 20, or 25.
4554dc88ebeSGabor Kovesdan.Sh SEE ALSO
4564dc88ebeSGabor Kovesdan.Xr ed 1 ,
4574dc88ebeSGabor Kovesdan.Xr ex 1 ,
4584dc88ebeSGabor Kovesdan.Xr gzip 1 ,
4594dc88ebeSGabor Kovesdan.Xr sed 1 ,
4604dc88ebeSGabor Kovesdan.Xr re_format 7
4614dc88ebeSGabor Kovesdan.Sh STANDARDS
4624dc88ebeSGabor KovesdanThe
4634dc88ebeSGabor Kovesdan.Nm
4644dc88ebeSGabor Kovesdanutility is compliant with the
4654dc88ebeSGabor Kovesdan.St -p1003.1-2008
4664dc88ebeSGabor Kovesdanspecification.
4674dc88ebeSGabor Kovesdan.Pp
4684dc88ebeSGabor KovesdanThe flags
4694dc88ebeSGabor Kovesdan.Op Fl AaBbCDdGHhIJLmoPRSUVwZ
4704dc88ebeSGabor Kovesdanare extensions to that specification, and the behaviour of the
4714dc88ebeSGabor Kovesdan.Fl f
4724dc88ebeSGabor Kovesdanflag when used with an empty pattern file is left undefined.
4734dc88ebeSGabor Kovesdan.Pp
4744dc88ebeSGabor KovesdanAll long options are provided for compatibility with
4754dc88ebeSGabor KovesdanGNU versions of this utility.
4764dc88ebeSGabor Kovesdan.Pp
4774dc88ebeSGabor KovesdanHistoric versions of the
4784dc88ebeSGabor Kovesdan.Nm grep
4794dc88ebeSGabor Kovesdanutility also supported the flags
4804dc88ebeSGabor Kovesdan.Op Fl ruy .
4814dc88ebeSGabor KovesdanThis implementation supports those options;
4824dc88ebeSGabor Kovesdanhowever, their use is strongly discouraged.
4834dc88ebeSGabor Kovesdan.Sh HISTORY
4844dc88ebeSGabor KovesdanThe
4854dc88ebeSGabor Kovesdan.Nm grep
4864dc88ebeSGabor Kovesdancommand first appeared in
4874dc88ebeSGabor Kovesdan.At v6 .
488