xref: /freebsd/usr.bin/grep/grep.1 (revision bf10f246fe6fc35cb00aa6add53de05d63cfabde)
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.\"
3355e44f51SGabor Kovesdan.Dd July 28, 2010
344dc88ebeSGabor Kovesdan.Dt GREP 1
354dc88ebeSGabor Kovesdan.Os
364dc88ebeSGabor Kovesdan.Sh NAME
37*bf10f246SConrad Meyer.Nm grep , egrep , fgrep , rgrep ,
384dc88ebeSGabor Kovesdan.Nm zgrep , zegrep , zfgrep
394dc88ebeSGabor Kovesdan.Nd file pattern searcher
404dc88ebeSGabor Kovesdan.Sh SYNOPSIS
414dc88ebeSGabor Kovesdan.Nm grep
424dc88ebeSGabor Kovesdan.Bk -words
434dc88ebeSGabor Kovesdan.Op Fl abcdDEFGHhIiJLlmnOopqRSsUVvwxZ
444dc88ebeSGabor Kovesdan.Op Fl A Ar num
454dc88ebeSGabor Kovesdan.Op Fl B Ar num
464dc88ebeSGabor Kovesdan.Op Fl C Ns Op Ar num
474dc88ebeSGabor Kovesdan.Op Fl e Ar pattern
484dc88ebeSGabor Kovesdan.Op Fl f Ar file
494dc88ebeSGabor Kovesdan.Op Fl Fl binary-files Ns = Ns Ar value
504dc88ebeSGabor Kovesdan.Op Fl Fl color Ns Op = Ns Ar when
514dc88ebeSGabor Kovesdan.Op Fl Fl colour Ns Op = Ns Ar when
524dc88ebeSGabor Kovesdan.Op Fl Fl context Ns Op = Ns Ar num
534dc88ebeSGabor Kovesdan.Op Fl Fl label
544dc88ebeSGabor Kovesdan.Op Fl Fl line-buffered
554dc88ebeSGabor Kovesdan.Op Fl Fl null
564dc88ebeSGabor Kovesdan.Op Ar pattern
574dc88ebeSGabor Kovesdan.Op Ar
584dc88ebeSGabor Kovesdan.Ek
594dc88ebeSGabor Kovesdan.Sh DESCRIPTION
604dc88ebeSGabor KovesdanThe
614dc88ebeSGabor Kovesdan.Nm grep
624dc88ebeSGabor Kovesdanutility searches any given input files,
634dc88ebeSGabor Kovesdanselecting lines that match one or more patterns.
644dc88ebeSGabor KovesdanBy default, a pattern matches an input line if the regular expression
654dc88ebeSGabor Kovesdan(RE) in the pattern matches the input line
664dc88ebeSGabor Kovesdanwithout its trailing newline.
674dc88ebeSGabor KovesdanAn empty expression matches every line.
684dc88ebeSGabor KovesdanEach input line that matches at least one of the patterns is written
694dc88ebeSGabor Kovesdanto the standard output.
704dc88ebeSGabor Kovesdan.Pp
714dc88ebeSGabor Kovesdan.Nm grep
724dc88ebeSGabor Kovesdanis used for simple patterns and
734dc88ebeSGabor Kovesdanbasic regular expressions
744dc88ebeSGabor Kovesdan.Pq BREs ;
754dc88ebeSGabor Kovesdan.Nm egrep
764dc88ebeSGabor Kovesdancan handle extended regular expressions
774dc88ebeSGabor Kovesdan.Pq EREs .
784dc88ebeSGabor KovesdanSee
794dc88ebeSGabor Kovesdan.Xr re_format 7
804dc88ebeSGabor Kovesdanfor more information on regular expressions.
814dc88ebeSGabor Kovesdan.Nm fgrep
824dc88ebeSGabor Kovesdanis quicker than both
834dc88ebeSGabor Kovesdan.Nm grep
844dc88ebeSGabor Kovesdanand
854dc88ebeSGabor Kovesdan.Nm egrep ,
864dc88ebeSGabor Kovesdanbut can only handle fixed patterns
874dc88ebeSGabor Kovesdan(i.e. it does not interpret regular expressions).
884dc88ebeSGabor KovesdanPatterns may consist of one or more lines,
894dc88ebeSGabor Kovesdanallowing any of the pattern lines to match a portion of the input.
904dc88ebeSGabor Kovesdan.Pp
914dc88ebeSGabor Kovesdan.Nm zgrep ,
924dc88ebeSGabor Kovesdan.Nm zegrep ,
934dc88ebeSGabor Kovesdanand
944dc88ebeSGabor Kovesdan.Nm zfgrep
954dc88ebeSGabor Kovesdanact like
964dc88ebeSGabor Kovesdan.Nm grep ,
974dc88ebeSGabor Kovesdan.Nm egrep ,
984dc88ebeSGabor Kovesdanand
994dc88ebeSGabor Kovesdan.Nm fgrep ,
1004dc88ebeSGabor Kovesdanrespectively, but accept input files compressed with the
1014dc88ebeSGabor Kovesdan.Xr compress 1
1024dc88ebeSGabor Kovesdanor
1034dc88ebeSGabor Kovesdan.Xr gzip 1
1044dc88ebeSGabor Kovesdancompression utilities.
1054dc88ebeSGabor Kovesdan.Pp
1064dc88ebeSGabor KovesdanThe following options are available:
1074dc88ebeSGabor Kovesdan.Bl -tag -width indent
1084dc88ebeSGabor Kovesdan.It Fl A Ar num , Fl Fl after-context Ns = Ns Ar num
1094dc88ebeSGabor KovesdanPrint
1104dc88ebeSGabor Kovesdan.Ar num
1114dc88ebeSGabor Kovesdanlines of trailing context after each match.
1124dc88ebeSGabor KovesdanSee also the
1134dc88ebeSGabor Kovesdan.Fl B
1144dc88ebeSGabor Kovesdanand
1154dc88ebeSGabor Kovesdan.Fl C
1164dc88ebeSGabor Kovesdanoptions.
1174dc88ebeSGabor Kovesdan.It Fl a , Fl Fl text
1184dc88ebeSGabor KovesdanTreat all files as ASCII text.
1194dc88ebeSGabor KovesdanNormally
1204dc88ebeSGabor Kovesdan.Nm
1214dc88ebeSGabor Kovesdanwill simply print
1224dc88ebeSGabor Kovesdan.Dq Binary file ... matches
1234dc88ebeSGabor Kovesdanif files contain binary characters.
1244dc88ebeSGabor KovesdanUse of this option forces
1254dc88ebeSGabor Kovesdan.Nm
1264dc88ebeSGabor Kovesdanto output lines matching the specified pattern.
1274dc88ebeSGabor Kovesdan.It Fl B Ar num , Fl Fl before-context Ns = Ns Ar num
1284dc88ebeSGabor KovesdanPrint
1294dc88ebeSGabor Kovesdan.Ar num
1304dc88ebeSGabor Kovesdanlines of leading context before each match.
1314dc88ebeSGabor KovesdanSee also the
1324dc88ebeSGabor Kovesdan.Fl A
1334dc88ebeSGabor Kovesdanand
1344dc88ebeSGabor Kovesdan.Fl C
1354dc88ebeSGabor Kovesdanoptions.
1364dc88ebeSGabor Kovesdan.It Fl b , Fl Fl byte-offset
1374dc88ebeSGabor KovesdanThe offset in bytes of a matched pattern is
1384dc88ebeSGabor Kovesdandisplayed in front of the respective matched line.
1394dc88ebeSGabor Kovesdan.It Fl C Ns Op Ar num , Fl Fl context Ns = Ns Ar num
1404dc88ebeSGabor KovesdanPrint
1414dc88ebeSGabor Kovesdan.Ar num
1424dc88ebeSGabor Kovesdanlines of leading and trailing context surrounding each match.
1434dc88ebeSGabor KovesdanThe default is 2 and is equivalent to
1444dc88ebeSGabor Kovesdan.Fl A
1454dc88ebeSGabor Kovesdan.Ar 2
1464dc88ebeSGabor Kovesdan.Fl B
1474dc88ebeSGabor Kovesdan.Ar 2 .
1484dc88ebeSGabor KovesdanNote:
1494dc88ebeSGabor Kovesdanno whitespace may be given between the option and its argument.
1504dc88ebeSGabor Kovesdan.It Fl c , Fl Fl count
1514dc88ebeSGabor KovesdanOnly a count of selected lines is written to standard output.
1524dc88ebeSGabor Kovesdan.It Fl Fl colour Ns = Ns Op Ar when , Fl Fl color Ns = Ns Op Ar when
1534dc88ebeSGabor KovesdanMark up the matching text with the expression stored in
1544dc88ebeSGabor Kovesdan.Ev GREP_COLOR
1554dc88ebeSGabor Kovesdanenvironment variable.
1564dc88ebeSGabor KovesdanThe possible values of when can be `never', `always' or `auto'.
1574dc88ebeSGabor Kovesdan.It Fl D Ar action , Fl Fl devices Ns = Ns Ar action
1584dc88ebeSGabor KovesdanSpecify the demanded action for devices, FIFOs and sockets.
1594dc88ebeSGabor KovesdanThe default action is `read', which means, that they are read
1604dc88ebeSGabor Kovesdanas if they were normal files.
1614dc88ebeSGabor KovesdanIf the action is set to `skip', devices will be silently skipped.
1624dc88ebeSGabor Kovesdan.It Fl d Ar action , Fl Fl directories Ns = Ns Ar action
1634dc88ebeSGabor KovesdanSpecify the demanded action for directories.
1644dc88ebeSGabor KovesdanIt is `read' by default, which means that the directories
1654dc88ebeSGabor Kovesdanare read in the same manner as normal files.
1664dc88ebeSGabor KovesdanOther possible values are `skip' to silently ignore the
1674dc88ebeSGabor Kovesdandirectories, and `recurse' to read them recursively, which
1684dc88ebeSGabor Kovesdanhas the same effect as the
1694dc88ebeSGabor Kovesdan.Fl R
1704dc88ebeSGabor Kovesdanand
1714dc88ebeSGabor Kovesdan.Fl r
1724dc88ebeSGabor Kovesdanoption.
1734dc88ebeSGabor Kovesdan.It Fl E , Fl Fl extended-regexp
1744dc88ebeSGabor KovesdanInterpret
1754dc88ebeSGabor Kovesdan.Ar pattern
1764dc88ebeSGabor Kovesdanas an extended regular expression
1774dc88ebeSGabor Kovesdan(i.e. force
1784dc88ebeSGabor Kovesdan.Nm grep
1794dc88ebeSGabor Kovesdanto behave as
1804dc88ebeSGabor Kovesdan.Nm egrep ) .
1814dc88ebeSGabor Kovesdan.It Fl e Ar pattern , Fl Fl regexp Ns = Ns Ar pattern
1824dc88ebeSGabor KovesdanSpecify a pattern used during the search of the input:
1834dc88ebeSGabor Kovesdanan input line is selected if it matches any of the specified patterns.
1844dc88ebeSGabor KovesdanThis option is most useful when multiple
1854dc88ebeSGabor Kovesdan.Fl e
1864dc88ebeSGabor Kovesdanoptions are used to specify multiple patterns,
1874dc88ebeSGabor Kovesdanor when a pattern begins with a dash
1884dc88ebeSGabor Kovesdan.Pq Sq - .
1894dc88ebeSGabor Kovesdan.It Fl Fl exclude
19055e44f51SGabor KovesdanIf specified, it excludes files matching the given
19155e44f51SGabor Kovesdanfilename pattern from the search.
19255e44f51SGabor KovesdanNote that
19355e44f51SGabor Kovesdan.Fl Fl exclude
19455e44f51SGabor Kovesdanpatterns take priority over
19555e44f51SGabor Kovesdan.Fl Fl include
19655e44f51SGabor Kovesdanpatterns, and if no
19755e44f51SGabor Kovesdan.Fl Fl include
19855e44f51SGabor Kovesdanpattern is specified, all files are searched that are
19955e44f51SGabor Kovesdannot excluded.
20055e44f51SGabor KovesdanPatterns are matched to the full path specified,
20155e44f51SGabor Kovesdannot only to the filename component.
2024dc88ebeSGabor Kovesdan.It Fl Fl exclude-dir
2034dc88ebeSGabor KovesdanIf
2044dc88ebeSGabor Kovesdan.Fl R
2054dc88ebeSGabor Kovesdanis specified, it excludes directories matching the
20655e44f51SGabor Kovesdangiven filename pattern from the search.
20755e44f51SGabor KovesdanNote that
20855e44f51SGabor Kovesdan.Fl Fl exclude-dir
20955e44f51SGabor Kovesdanpatterns take priority over
21055e44f51SGabor Kovesdan.Fl Fl include-dir
21155e44f51SGabor Kovesdanpatterns, and if no
21255e44f51SGabor Kovesdan.Fl Fl include-dir
21355e44f51SGabor Kovesdanpattern is specified, all directories are searched that are
21455e44f51SGabor Kovesdannot excluded.
2154dc88ebeSGabor Kovesdan.It Fl F , Fl Fl fixed-strings
2164dc88ebeSGabor KovesdanInterpret
2174dc88ebeSGabor Kovesdan.Ar pattern
2184dc88ebeSGabor Kovesdanas a set of fixed strings
2194dc88ebeSGabor Kovesdan(i.e. force
2204dc88ebeSGabor Kovesdan.Nm grep
2214dc88ebeSGabor Kovesdanto behave as
2224dc88ebeSGabor Kovesdan.Nm fgrep ) .
2234dc88ebeSGabor Kovesdan.It Fl f Ar file , Fl Fl file Ns = Ns Ar file
2244dc88ebeSGabor KovesdanRead one or more newline separated patterns from
2254dc88ebeSGabor Kovesdan.Ar file .
2264dc88ebeSGabor KovesdanEmpty pattern lines match every input line.
2274dc88ebeSGabor KovesdanNewlines are not considered part of a pattern.
2284dc88ebeSGabor KovesdanIf
2294dc88ebeSGabor Kovesdan.Ar file
2304dc88ebeSGabor Kovesdanis empty, nothing is matched.
2314dc88ebeSGabor Kovesdan.It Fl G , Fl Fl basic-regexp
2324dc88ebeSGabor KovesdanInterpret
2334dc88ebeSGabor Kovesdan.Ar pattern
2344dc88ebeSGabor Kovesdanas a basic regular expression
2354dc88ebeSGabor Kovesdan(i.e. force
2364dc88ebeSGabor Kovesdan.Nm grep
2374dc88ebeSGabor Kovesdanto behave as traditional
2384dc88ebeSGabor Kovesdan.Nm grep ) .
2394dc88ebeSGabor Kovesdan.It Fl H
2404dc88ebeSGabor KovesdanAlways print filename headers with output lines.
2414dc88ebeSGabor Kovesdan.It Fl h , Fl Fl no-filename
2424dc88ebeSGabor KovesdanNever print filename headers
2434dc88ebeSGabor Kovesdan.Pq i.e. filenames
2444dc88ebeSGabor Kovesdanwith output lines.
2454dc88ebeSGabor Kovesdan.It Fl Fl help
2464dc88ebeSGabor KovesdanPrint a brief help message.
2474dc88ebeSGabor Kovesdan.It Fl I
2484dc88ebeSGabor KovesdanIgnore binary files.
2494dc88ebeSGabor KovesdanThis option is equivalent to
2504dc88ebeSGabor Kovesdan.Fl Fl binary-file Ns = Ns Ar without-match
2514dc88ebeSGabor Kovesdanoption.
2524dc88ebeSGabor Kovesdan.It Fl i , Fl Fl ignore-case
2534dc88ebeSGabor KovesdanPerform case insensitive matching.
2544dc88ebeSGabor KovesdanBy default,
2554dc88ebeSGabor Kovesdan.Nm grep
2564dc88ebeSGabor Kovesdanis case sensitive.
2574dc88ebeSGabor Kovesdan.It Fl Fl include
25855e44f51SGabor KovesdanIf specified, only files matching the
25955e44f51SGabor Kovesdangiven filename pattern are searched.
26055e44f51SGabor KovesdanNote that
26155e44f51SGabor Kovesdan.Fl Fl exclude
26255e44f51SGabor Kovesdanpatterns take priority over
26355e44f51SGabor Kovesdan.Fl Fl include
26455e44f51SGabor Kovesdanpatterns.
26555e44f51SGabor KovesdanPatterns are matched to the full path specified,
26655e44f51SGabor Kovesdannot only to the filename component.
2674dc88ebeSGabor Kovesdan.It Fl Fl include-dir
2684dc88ebeSGabor KovesdanIf
2694dc88ebeSGabor Kovesdan.Fl R
27055e44f51SGabor Kovesdanis specified, only directories matching the
27155e44f51SGabor Kovesdangiven filename pattern are searched.
27255e44f51SGabor KovesdanNote that
27355e44f51SGabor Kovesdan.Fl Fl exclude-dir
27455e44f51SGabor Kovesdanpatterns take priority over
27555e44f51SGabor Kovesdan.Fl Fl include-dir
27655e44f51SGabor Kovesdanpatterns.
2774dc88ebeSGabor Kovesdan.It Fl J, Fl Fl bz2decompress
2784dc88ebeSGabor KovesdanDecompress the
2794dc88ebeSGabor Kovesdan.Xr bzip2 1
2804dc88ebeSGabor Kovesdancompressed file before looking for the text.
2814dc88ebeSGabor Kovesdan.It Fl L , Fl Fl files-without-match
2824dc88ebeSGabor KovesdanOnly the names of files not containing selected lines are written to
2834dc88ebeSGabor Kovesdanstandard output.
2844dc88ebeSGabor KovesdanPathnames are listed once per file searched.
2854dc88ebeSGabor KovesdanIf the standard input is searched, the string
2864dc88ebeSGabor Kovesdan.Dq (standard input)
2874dc88ebeSGabor Kovesdanis written.
2884dc88ebeSGabor Kovesdan.It Fl l , Fl Fl files-with-matches
2894dc88ebeSGabor KovesdanOnly the names of files containing selected lines are written to
2904dc88ebeSGabor Kovesdanstandard output.
2914dc88ebeSGabor Kovesdan.Nm grep
2924dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
2934dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
2944dc88ebeSGabor KovesdanPathnames are listed once per file searched.
2954dc88ebeSGabor KovesdanIf the standard input is searched, the string
2964dc88ebeSGabor Kovesdan.Dq (standard input)
2974dc88ebeSGabor Kovesdanis written.
2984dc88ebeSGabor Kovesdan.It Fl Fl mmap
2994dc88ebeSGabor KovesdanUse
3004dc88ebeSGabor Kovesdan.Xr mmap 2
3014dc88ebeSGabor Kovesdaninstead of
3024dc88ebeSGabor Kovesdan.Xr read 2
3034dc88ebeSGabor Kovesdanto read input, which can result in better performance under some
304a4f5b3dfSJoel Dahlcircumstances but can cause undefined behaviour.
3054dc88ebeSGabor Kovesdan.It Fl m Ar num, Fl Fl max-count Ns = Ns Ar num
3064dc88ebeSGabor KovesdanStop reading the file after
3074dc88ebeSGabor Kovesdan.Ar num
3084dc88ebeSGabor Kovesdanmatches.
3094dc88ebeSGabor Kovesdan.It Fl n , Fl Fl line-number
3104dc88ebeSGabor KovesdanEach output line is preceded by its relative line number in the file,
3114dc88ebeSGabor Kovesdanstarting at line 1.
3124dc88ebeSGabor KovesdanThe line number counter is reset for each file processed.
3134dc88ebeSGabor KovesdanThis option is ignored if
3144dc88ebeSGabor Kovesdan.Fl c ,
3154dc88ebeSGabor Kovesdan.Fl L ,
3164dc88ebeSGabor Kovesdan.Fl l ,
3174dc88ebeSGabor Kovesdanor
3184dc88ebeSGabor Kovesdan.Fl q
3194dc88ebeSGabor Kovesdanis
3204dc88ebeSGabor Kovesdanspecified.
3214dc88ebeSGabor Kovesdan.It Fl Fl null
3224dc88ebeSGabor KovesdanPrints a zero-byte after the file name.
3234dc88ebeSGabor Kovesdan.It Fl O
3244dc88ebeSGabor KovesdanIf
3254dc88ebeSGabor Kovesdan.Fl R
3264dc88ebeSGabor Kovesdanis specified, follow symbolic links only if they were explicitly listed
3274dc88ebeSGabor Kovesdanon the command line.
3284dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
3294dc88ebeSGabor Kovesdan.It Fl o, Fl Fl only-matching
3304dc88ebeSGabor KovesdanPrints only the matching part of the lines.
3314dc88ebeSGabor Kovesdan.It Fl p
3324dc88ebeSGabor KovesdanIf
3334dc88ebeSGabor Kovesdan.Fl R
3344dc88ebeSGabor Kovesdanis specified, no symbolic links are followed.
3354dc88ebeSGabor KovesdanThis is the default.
3364dc88ebeSGabor Kovesdan.It Fl q , Fl Fl quiet , Fl Fl silent
3374dc88ebeSGabor KovesdanQuiet mode:
3384dc88ebeSGabor Kovesdansuppress normal output.
3394dc88ebeSGabor Kovesdan.Nm grep
3404dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
3414dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
3424dc88ebeSGabor Kovesdan.It Fl R , Fl r , Fl Fl recursive
3434dc88ebeSGabor KovesdanRecursively search subdirectories listed.
344*bf10f246SConrad Meyer(i.e. force
345*bf10f246SConrad Meyer.Nm grep
346*bf10f246SConrad Meyerto behave as
347*bf10f246SConrad Meyer.Nm rgrep ) .
3484dc88ebeSGabor Kovesdan.It Fl S
3494dc88ebeSGabor KovesdanIf
3504dc88ebeSGabor Kovesdan.Fl R
3514dc88ebeSGabor Kovesdanis specified, all symbolic links are followed.
3524dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
3534dc88ebeSGabor Kovesdan.It Fl s , Fl Fl no-messages
3544dc88ebeSGabor KovesdanSilent mode.
3554dc88ebeSGabor KovesdanNonexistent and unreadable files are ignored
3564dc88ebeSGabor Kovesdan(i.e. their error messages are suppressed).
3574dc88ebeSGabor Kovesdan.It Fl U , Fl Fl binary
3584dc88ebeSGabor KovesdanSearch binary files, but do not attempt to print them.
3596b91f517SEd Maste.It Fl u
3606b91f517SEd MasteThis option has no effect and is provided only for compatibility with GNU grep.
3614dc88ebeSGabor Kovesdan.It Fl V , Fl Fl version
3624dc88ebeSGabor KovesdanDisplay version information and exit.
3634dc88ebeSGabor Kovesdan.It Fl v , Fl Fl invert-match
3644dc88ebeSGabor KovesdanSelected lines are those
3654dc88ebeSGabor Kovesdan.Em not
3664dc88ebeSGabor Kovesdanmatching any of the specified patterns.
3674dc88ebeSGabor Kovesdan.It Fl w , Fl Fl word-regexp
3684dc88ebeSGabor KovesdanThe expression is searched for as a word (as if surrounded by
3694dc88ebeSGabor Kovesdan.Sq [[:<:]]
3704dc88ebeSGabor Kovesdanand
3714dc88ebeSGabor Kovesdan.Sq [[:>:]] ;
3724dc88ebeSGabor Kovesdansee
3734dc88ebeSGabor Kovesdan.Xr re_format 7 ) .
3744dc88ebeSGabor Kovesdan.It Fl x , Fl Fl line-regexp
3754dc88ebeSGabor KovesdanOnly input lines selected against an entire fixed string or regular
3764dc88ebeSGabor Kovesdanexpression are considered to be matching lines.
3774dc88ebeSGabor Kovesdan.It Fl y
3784dc88ebeSGabor KovesdanEquivalent to
3794dc88ebeSGabor Kovesdan.Fl i .
3804dc88ebeSGabor KovesdanObsoleted.
3814dc88ebeSGabor Kovesdan.It Fl Z , Fl z , Fl Fl decompress
3824dc88ebeSGabor KovesdanForce
3834dc88ebeSGabor Kovesdan.Nm grep
3844dc88ebeSGabor Kovesdanto behave as
3854dc88ebeSGabor Kovesdan.Nm zgrep .
3864dc88ebeSGabor Kovesdan.It Fl Fl binary-files Ns = Ns Ar value
3874dc88ebeSGabor KovesdanControls searching and printing of binary files.
3884dc88ebeSGabor KovesdanOptions are
3894dc88ebeSGabor Kovesdan.Ar binary ,
3904dc88ebeSGabor Kovesdanthe default: search binary files but do not print them;
3914dc88ebeSGabor Kovesdan.Ar without-match :
3924dc88ebeSGabor Kovesdando not search binary files;
3934dc88ebeSGabor Kovesdanand
3944dc88ebeSGabor Kovesdan.Ar text :
3954dc88ebeSGabor Kovesdantreat all files as text.
3964dc88ebeSGabor Kovesdan.Sm off
3974dc88ebeSGabor Kovesdan.It Fl Fl context Op = Ar num
3984dc88ebeSGabor Kovesdan.Sm on
3994dc88ebeSGabor KovesdanPrint
4004dc88ebeSGabor Kovesdan.Ar num
4014dc88ebeSGabor Kovesdanlines of leading and trailing context.
4024dc88ebeSGabor KovesdanThe default is 2.
4034dc88ebeSGabor Kovesdan.It Fl Fl line-buffered
4044dc88ebeSGabor KovesdanForce output to be line buffered.
4054dc88ebeSGabor KovesdanBy default, output is line buffered when standard output is a terminal
4064dc88ebeSGabor Kovesdanand block buffered otherwise.
4074dc88ebeSGabor Kovesdan.El
4087e700c30SJoel Dahl.Pp
4094dc88ebeSGabor KovesdanIf no file arguments are specified, the standard input is used.
410e9a67923SGabor Kovesdan.Sh EXIT STATUS
4114dc88ebeSGabor KovesdanThe
4124dc88ebeSGabor Kovesdan.Nm grep
4134dc88ebeSGabor Kovesdanutility exits with one of the following values:
4144dc88ebeSGabor Kovesdan.Pp
4154dc88ebeSGabor Kovesdan.Bl -tag -width flag -compact
4164dc88ebeSGabor Kovesdan.It Li 0
4174dc88ebeSGabor KovesdanOne or more lines were selected.
4184dc88ebeSGabor Kovesdan.It Li 1
4194dc88ebeSGabor KovesdanNo lines were selected.
4204dc88ebeSGabor Kovesdan.It Li \*(Gt1
4214dc88ebeSGabor KovesdanAn error occurred.
4224dc88ebeSGabor Kovesdan.El
4234dc88ebeSGabor Kovesdan.Sh EXAMPLES
4244dc88ebeSGabor KovesdanTo find all occurrences of the word
4254dc88ebeSGabor Kovesdan.Sq patricia
4264dc88ebeSGabor Kovesdanin a file:
4274dc88ebeSGabor Kovesdan.Pp
4284dc88ebeSGabor Kovesdan.Dl $ grep 'patricia' myfile
4294dc88ebeSGabor Kovesdan.Pp
4304dc88ebeSGabor KovesdanTo find all occurrences of the pattern
4314dc88ebeSGabor Kovesdan.Ql .Pp
4324dc88ebeSGabor Kovesdanat the beginning of a line:
4334dc88ebeSGabor Kovesdan.Pp
4344dc88ebeSGabor Kovesdan.Dl $ grep '^\e.Pp' myfile
4354dc88ebeSGabor Kovesdan.Pp
4364dc88ebeSGabor KovesdanThe apostrophes ensure the entire expression is evaluated by
4374dc88ebeSGabor Kovesdan.Nm grep
4384dc88ebeSGabor Kovesdaninstead of by the user's shell.
4394dc88ebeSGabor KovesdanThe caret
4404dc88ebeSGabor Kovesdan.Ql ^
4414dc88ebeSGabor Kovesdanmatches the null string at the beginning of a line,
4424dc88ebeSGabor Kovesdanand the
4434dc88ebeSGabor Kovesdan.Ql \e
4444dc88ebeSGabor Kovesdanescapes the
4454dc88ebeSGabor Kovesdan.Ql \&. ,
4464dc88ebeSGabor Kovesdanwhich would otherwise match any character.
4474dc88ebeSGabor Kovesdan.Pp
4484dc88ebeSGabor KovesdanTo find all lines in a file which do not contain the words
4494dc88ebeSGabor Kovesdan.Sq foo
4504dc88ebeSGabor Kovesdanor
4514dc88ebeSGabor Kovesdan.Sq bar :
4524dc88ebeSGabor Kovesdan.Pp
4534dc88ebeSGabor Kovesdan.Dl $ grep -v -e 'foo' -e 'bar' myfile
4544dc88ebeSGabor Kovesdan.Pp
4554dc88ebeSGabor KovesdanA simple example of an extended regular expression:
4564dc88ebeSGabor Kovesdan.Pp
4574dc88ebeSGabor Kovesdan.Dl $ egrep '19|20|25' calendar
4584dc88ebeSGabor Kovesdan.Pp
4594dc88ebeSGabor KovesdanPeruses the file
4604dc88ebeSGabor Kovesdan.Sq calendar
4614dc88ebeSGabor Kovesdanlooking for either 19, 20, or 25.
4624dc88ebeSGabor Kovesdan.Sh SEE ALSO
4634dc88ebeSGabor Kovesdan.Xr ed 1 ,
4644dc88ebeSGabor Kovesdan.Xr ex 1 ,
4654dc88ebeSGabor Kovesdan.Xr gzip 1 ,
4664dc88ebeSGabor Kovesdan.Xr sed 1 ,
4674dc88ebeSGabor Kovesdan.Xr re_format 7
4684dc88ebeSGabor Kovesdan.Sh STANDARDS
4694dc88ebeSGabor KovesdanThe
4704dc88ebeSGabor Kovesdan.Nm
4714dc88ebeSGabor Kovesdanutility is compliant with the
4724dc88ebeSGabor Kovesdan.St -p1003.1-2008
4734dc88ebeSGabor Kovesdanspecification.
4744dc88ebeSGabor Kovesdan.Pp
4754dc88ebeSGabor KovesdanThe flags
4764dc88ebeSGabor Kovesdan.Op Fl AaBbCDdGHhIJLmoPRSUVwZ
4774dc88ebeSGabor Kovesdanare extensions to that specification, and the behaviour of the
4784dc88ebeSGabor Kovesdan.Fl f
4794dc88ebeSGabor Kovesdanflag when used with an empty pattern file is left undefined.
4804dc88ebeSGabor Kovesdan.Pp
4814dc88ebeSGabor KovesdanAll long options are provided for compatibility with
4824dc88ebeSGabor KovesdanGNU versions of this utility.
4834dc88ebeSGabor Kovesdan.Pp
4844dc88ebeSGabor KovesdanHistoric versions of the
4854dc88ebeSGabor Kovesdan.Nm grep
4864dc88ebeSGabor Kovesdanutility also supported the flags
4874dc88ebeSGabor Kovesdan.Op Fl ruy .
4884dc88ebeSGabor KovesdanThis implementation supports those options;
4894dc88ebeSGabor Kovesdanhowever, their use is strongly discouraged.
4904dc88ebeSGabor Kovesdan.Sh HISTORY
4914dc88ebeSGabor KovesdanThe
4924dc88ebeSGabor Kovesdan.Nm grep
4934dc88ebeSGabor Kovesdancommand first appeared in
4944dc88ebeSGabor Kovesdan.At v6 .
495