xref: /freebsd/usr.bin/grep/grep.1 (revision 4a5b4207385cabd19d4123e949dcff01211d0c58)
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.\"
33*4a5b4207SBaptiste 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
42*4a5b4207SBaptiste 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
17855e44f51SGabor Kovesdanpatterns take priority over
17955e44f51SGabor Kovesdan.Fl Fl include
18055e44f51SGabor Kovesdanpatterns, and if no
18155e44f51SGabor Kovesdan.Fl Fl include
18255e44f51SGabor Kovesdanpattern is specified, all files are searched that are
18355e44f51SGabor Kovesdannot excluded.
18455e44f51SGabor KovesdanPatterns are matched to the full path specified,
18555e44f51SGabor Kovesdannot only to the filename component.
1864dc88ebeSGabor Kovesdan.It Fl Fl exclude-dir
1874dc88ebeSGabor KovesdanIf
1884dc88ebeSGabor Kovesdan.Fl R
1894dc88ebeSGabor Kovesdanis specified, it excludes directories matching the
19055e44f51SGabor Kovesdangiven filename pattern from the search.
19155e44f51SGabor KovesdanNote that
19255e44f51SGabor Kovesdan.Fl Fl exclude-dir
19355e44f51SGabor Kovesdanpatterns take priority over
19455e44f51SGabor Kovesdan.Fl Fl include-dir
19555e44f51SGabor Kovesdanpatterns, and if no
19655e44f51SGabor Kovesdan.Fl Fl include-dir
19755e44f51SGabor Kovesdanpattern is specified, all directories are searched that are
19855e44f51SGabor Kovesdannot excluded.
1994dc88ebeSGabor Kovesdan.It Fl F , Fl Fl fixed-strings
2004dc88ebeSGabor KovesdanInterpret
2014dc88ebeSGabor Kovesdan.Ar pattern
2024dc88ebeSGabor Kovesdanas a set of fixed strings
2034dc88ebeSGabor Kovesdan(i.e. force
2044dc88ebeSGabor Kovesdan.Nm grep
2054dc88ebeSGabor Kovesdanto behave as
2064dc88ebeSGabor Kovesdan.Nm fgrep ) .
2074dc88ebeSGabor Kovesdan.It Fl f Ar file , Fl Fl file Ns = Ns Ar file
2084dc88ebeSGabor KovesdanRead one or more newline separated patterns from
2094dc88ebeSGabor Kovesdan.Ar file .
2104dc88ebeSGabor KovesdanEmpty pattern lines match every input line.
2114dc88ebeSGabor KovesdanNewlines are not considered part of a pattern.
2124dc88ebeSGabor KovesdanIf
2134dc88ebeSGabor Kovesdan.Ar file
2144dc88ebeSGabor Kovesdanis empty, nothing is matched.
2154dc88ebeSGabor Kovesdan.It Fl G , Fl Fl basic-regexp
2164dc88ebeSGabor KovesdanInterpret
2174dc88ebeSGabor Kovesdan.Ar pattern
2184dc88ebeSGabor Kovesdanas a basic regular expression
2194dc88ebeSGabor Kovesdan(i.e. force
2204dc88ebeSGabor Kovesdan.Nm grep
2214dc88ebeSGabor Kovesdanto behave as traditional
2224dc88ebeSGabor Kovesdan.Nm grep ) .
2234dc88ebeSGabor Kovesdan.It Fl H
2244dc88ebeSGabor KovesdanAlways print filename headers with output lines.
2254dc88ebeSGabor Kovesdan.It Fl h , Fl Fl no-filename
2264dc88ebeSGabor KovesdanNever print filename headers
2274dc88ebeSGabor Kovesdan.Pq i.e. filenames
2284dc88ebeSGabor Kovesdanwith output lines.
2294dc88ebeSGabor Kovesdan.It Fl Fl help
2304dc88ebeSGabor KovesdanPrint a brief help message.
2314dc88ebeSGabor Kovesdan.It Fl I
2324dc88ebeSGabor KovesdanIgnore binary files.
2334dc88ebeSGabor KovesdanThis option is equivalent to
2344dc88ebeSGabor Kovesdan.Fl Fl binary-file Ns = Ns Ar without-match
2354dc88ebeSGabor Kovesdanoption.
2364dc88ebeSGabor Kovesdan.It Fl i , Fl Fl ignore-case
2374dc88ebeSGabor KovesdanPerform case insensitive matching.
2384dc88ebeSGabor KovesdanBy default,
2394dc88ebeSGabor Kovesdan.Nm grep
2404dc88ebeSGabor Kovesdanis case sensitive.
2414dc88ebeSGabor Kovesdan.It Fl Fl include
24255e44f51SGabor KovesdanIf specified, only files matching the
24355e44f51SGabor Kovesdangiven filename pattern are searched.
24455e44f51SGabor KovesdanNote that
24555e44f51SGabor Kovesdan.Fl Fl exclude
24655e44f51SGabor Kovesdanpatterns take priority over
24755e44f51SGabor Kovesdan.Fl Fl include
24855e44f51SGabor Kovesdanpatterns.
24955e44f51SGabor KovesdanPatterns are matched to the full path specified,
25055e44f51SGabor Kovesdannot only to the filename component.
2514dc88ebeSGabor Kovesdan.It Fl Fl include-dir
2524dc88ebeSGabor KovesdanIf
2534dc88ebeSGabor Kovesdan.Fl R
25455e44f51SGabor Kovesdanis specified, only directories matching the
25555e44f51SGabor Kovesdangiven filename pattern are searched.
25655e44f51SGabor KovesdanNote that
25755e44f51SGabor Kovesdan.Fl Fl exclude-dir
25855e44f51SGabor Kovesdanpatterns take priority over
25955e44f51SGabor Kovesdan.Fl Fl include-dir
26055e44f51SGabor Kovesdanpatterns.
2614dc88ebeSGabor Kovesdan.It Fl L , Fl Fl files-without-match
2624dc88ebeSGabor KovesdanOnly the names of files not containing selected lines are written to
2634dc88ebeSGabor Kovesdanstandard output.
2644dc88ebeSGabor KovesdanPathnames are listed once per file searched.
2654dc88ebeSGabor KovesdanIf the standard input is searched, the string
2664dc88ebeSGabor Kovesdan.Dq (standard input)
2674dc88ebeSGabor Kovesdanis written.
2684dc88ebeSGabor Kovesdan.It Fl l , Fl Fl files-with-matches
2694dc88ebeSGabor KovesdanOnly the names of files containing selected lines are written to
2704dc88ebeSGabor Kovesdanstandard output.
2714dc88ebeSGabor Kovesdan.Nm grep
2724dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
2734dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
2744dc88ebeSGabor KovesdanPathnames are listed once per file searched.
2754dc88ebeSGabor KovesdanIf the standard input is searched, the string
2764dc88ebeSGabor Kovesdan.Dq (standard input)
2774dc88ebeSGabor Kovesdanis written.
2784dc88ebeSGabor Kovesdan.It Fl Fl mmap
2794dc88ebeSGabor KovesdanUse
2804dc88ebeSGabor Kovesdan.Xr mmap 2
2814dc88ebeSGabor Kovesdaninstead of
2824dc88ebeSGabor Kovesdan.Xr read 2
2834dc88ebeSGabor Kovesdanto read input, which can result in better performance under some
284a4f5b3dfSJoel Dahlcircumstances but can cause undefined behaviour.
2854dc88ebeSGabor Kovesdan.It Fl m Ar num, Fl Fl max-count Ns = Ns Ar num
2864dc88ebeSGabor KovesdanStop reading the file after
2874dc88ebeSGabor Kovesdan.Ar num
2884dc88ebeSGabor Kovesdanmatches.
2894dc88ebeSGabor Kovesdan.It Fl n , Fl Fl line-number
2904dc88ebeSGabor KovesdanEach output line is preceded by its relative line number in the file,
2914dc88ebeSGabor Kovesdanstarting at line 1.
2924dc88ebeSGabor KovesdanThe line number counter is reset for each file processed.
2934dc88ebeSGabor KovesdanThis option is ignored if
2944dc88ebeSGabor Kovesdan.Fl c ,
2954dc88ebeSGabor Kovesdan.Fl L ,
2964dc88ebeSGabor Kovesdan.Fl l ,
2974dc88ebeSGabor Kovesdanor
2984dc88ebeSGabor Kovesdan.Fl q
2994dc88ebeSGabor Kovesdanis
3004dc88ebeSGabor Kovesdanspecified.
3014dc88ebeSGabor Kovesdan.It Fl Fl null
3024dc88ebeSGabor KovesdanPrints a zero-byte after the file name.
3034dc88ebeSGabor Kovesdan.It Fl O
3044dc88ebeSGabor KovesdanIf
3054dc88ebeSGabor Kovesdan.Fl R
3064dc88ebeSGabor Kovesdanis specified, follow symbolic links only if they were explicitly listed
3074dc88ebeSGabor Kovesdanon the command line.
3084dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
3094dc88ebeSGabor Kovesdan.It Fl o, Fl Fl only-matching
3104dc88ebeSGabor KovesdanPrints only the matching part of the lines.
3114dc88ebeSGabor Kovesdan.It Fl p
3124dc88ebeSGabor KovesdanIf
3134dc88ebeSGabor Kovesdan.Fl R
3144dc88ebeSGabor Kovesdanis specified, no symbolic links are followed.
3154dc88ebeSGabor KovesdanThis is the default.
3164dc88ebeSGabor Kovesdan.It Fl q , Fl Fl quiet , Fl Fl silent
3174dc88ebeSGabor KovesdanQuiet mode:
3184dc88ebeSGabor Kovesdansuppress normal output.
3194dc88ebeSGabor Kovesdan.Nm grep
3204dc88ebeSGabor Kovesdanwill only search a file until a match has been found,
3214dc88ebeSGabor Kovesdanmaking searches potentially less expensive.
3224dc88ebeSGabor Kovesdan.It Fl R , Fl r , Fl Fl recursive
3234dc88ebeSGabor KovesdanRecursively search subdirectories listed.
324bf10f246SConrad Meyer(i.e. force
325bf10f246SConrad Meyer.Nm grep
326bf10f246SConrad Meyerto behave as
327bf10f246SConrad Meyer.Nm rgrep ) .
3284dc88ebeSGabor Kovesdan.It Fl S
3294dc88ebeSGabor KovesdanIf
3304dc88ebeSGabor Kovesdan.Fl R
3314dc88ebeSGabor Kovesdanis specified, all symbolic links are followed.
3324dc88ebeSGabor KovesdanThe default is not to follow symbolic links.
3334dc88ebeSGabor Kovesdan.It Fl s , Fl Fl no-messages
3344dc88ebeSGabor KovesdanSilent mode.
3354dc88ebeSGabor KovesdanNonexistent and unreadable files are ignored
3364dc88ebeSGabor Kovesdan(i.e. their error messages are suppressed).
3374dc88ebeSGabor Kovesdan.It Fl U , Fl Fl binary
3384dc88ebeSGabor KovesdanSearch binary files, but do not attempt to print them.
3396b91f517SEd Maste.It Fl u
3406b91f517SEd MasteThis option has no effect and is provided only for compatibility with GNU grep.
3414dc88ebeSGabor Kovesdan.It Fl V , Fl Fl version
3424dc88ebeSGabor KovesdanDisplay version information and exit.
3434dc88ebeSGabor Kovesdan.It Fl v , Fl Fl invert-match
3444dc88ebeSGabor KovesdanSelected lines are those
3454dc88ebeSGabor Kovesdan.Em not
3464dc88ebeSGabor Kovesdanmatching any of the specified patterns.
3474dc88ebeSGabor Kovesdan.It Fl w , Fl Fl word-regexp
3484dc88ebeSGabor KovesdanThe expression is searched for as a word (as if surrounded by
3494dc88ebeSGabor Kovesdan.Sq [[:<:]]
3504dc88ebeSGabor Kovesdanand
3514dc88ebeSGabor Kovesdan.Sq [[:>:]] ;
3524dc88ebeSGabor Kovesdansee
3534dc88ebeSGabor Kovesdan.Xr re_format 7 ) .
3544dc88ebeSGabor Kovesdan.It Fl x , Fl Fl line-regexp
3554dc88ebeSGabor KovesdanOnly input lines selected against an entire fixed string or regular
3564dc88ebeSGabor Kovesdanexpression are considered to be matching lines.
3574dc88ebeSGabor Kovesdan.It Fl y
3584dc88ebeSGabor KovesdanEquivalent to
3594dc88ebeSGabor Kovesdan.Fl i .
3604dc88ebeSGabor KovesdanObsoleted.
3615ee1ea02SEd Maste.It Fl z , Fl Fl null-data
3625ee1ea02SEd MasteTreat input and output data as sequences of lines terminated by a
3635ee1ea02SEd Mastezero-byte instead of a newline.
3644dc88ebeSGabor Kovesdan.It Fl Fl binary-files Ns = Ns Ar value
3654dc88ebeSGabor KovesdanControls searching and printing of binary files.
3664dc88ebeSGabor KovesdanOptions are
3674dc88ebeSGabor Kovesdan.Ar binary ,
3684dc88ebeSGabor Kovesdanthe default: search binary files but do not print them;
3694dc88ebeSGabor Kovesdan.Ar without-match :
3704dc88ebeSGabor Kovesdando not search binary files;
3714dc88ebeSGabor Kovesdanand
3724dc88ebeSGabor Kovesdan.Ar text :
3734dc88ebeSGabor Kovesdantreat all files as text.
3744dc88ebeSGabor Kovesdan.Sm off
3754dc88ebeSGabor Kovesdan.It Fl Fl context Op = Ar num
3764dc88ebeSGabor Kovesdan.Sm on
3774dc88ebeSGabor KovesdanPrint
3784dc88ebeSGabor Kovesdan.Ar num
3794dc88ebeSGabor Kovesdanlines of leading and trailing context.
3804dc88ebeSGabor KovesdanThe default is 2.
3814dc88ebeSGabor Kovesdan.It Fl Fl line-buffered
3824dc88ebeSGabor KovesdanForce output to be line buffered.
3834dc88ebeSGabor KovesdanBy default, output is line buffered when standard output is a terminal
3844dc88ebeSGabor Kovesdanand block buffered otherwise.
3854dc88ebeSGabor Kovesdan.El
3867e700c30SJoel Dahl.Pp
3874dc88ebeSGabor KovesdanIf no file arguments are specified, the standard input is used.
388e9a67923SGabor Kovesdan.Sh EXIT STATUS
3894dc88ebeSGabor KovesdanThe
3904dc88ebeSGabor Kovesdan.Nm grep
3914dc88ebeSGabor Kovesdanutility exits with one of the following values:
3924dc88ebeSGabor Kovesdan.Pp
3934dc88ebeSGabor Kovesdan.Bl -tag -width flag -compact
3944dc88ebeSGabor Kovesdan.It Li 0
3954dc88ebeSGabor KovesdanOne or more lines were selected.
3964dc88ebeSGabor Kovesdan.It Li 1
3974dc88ebeSGabor KovesdanNo lines were selected.
3984dc88ebeSGabor Kovesdan.It Li \*(Gt1
3994dc88ebeSGabor KovesdanAn error occurred.
4004dc88ebeSGabor Kovesdan.El
4014dc88ebeSGabor Kovesdan.Sh EXAMPLES
4024dc88ebeSGabor KovesdanTo find all occurrences of the word
4034dc88ebeSGabor Kovesdan.Sq patricia
4044dc88ebeSGabor Kovesdanin a file:
4054dc88ebeSGabor Kovesdan.Pp
4064dc88ebeSGabor Kovesdan.Dl $ grep 'patricia' myfile
4074dc88ebeSGabor Kovesdan.Pp
4084dc88ebeSGabor KovesdanTo find all occurrences of the pattern
4094dc88ebeSGabor Kovesdan.Ql .Pp
4104dc88ebeSGabor Kovesdanat the beginning of a line:
4114dc88ebeSGabor Kovesdan.Pp
4124dc88ebeSGabor Kovesdan.Dl $ grep '^\e.Pp' myfile
4134dc88ebeSGabor Kovesdan.Pp
4144dc88ebeSGabor KovesdanThe apostrophes ensure the entire expression is evaluated by
4154dc88ebeSGabor Kovesdan.Nm grep
4164dc88ebeSGabor Kovesdaninstead of by the user's shell.
4174dc88ebeSGabor KovesdanThe caret
4184dc88ebeSGabor Kovesdan.Ql ^
4194dc88ebeSGabor Kovesdanmatches the null string at the beginning of a line,
4204dc88ebeSGabor Kovesdanand the
4214dc88ebeSGabor Kovesdan.Ql \e
4224dc88ebeSGabor Kovesdanescapes the
4234dc88ebeSGabor Kovesdan.Ql \&. ,
4244dc88ebeSGabor Kovesdanwhich would otherwise match any character.
4254dc88ebeSGabor Kovesdan.Pp
4264dc88ebeSGabor KovesdanTo find all lines in a file which do not contain the words
4274dc88ebeSGabor Kovesdan.Sq foo
4284dc88ebeSGabor Kovesdanor
4294dc88ebeSGabor Kovesdan.Sq bar :
4304dc88ebeSGabor Kovesdan.Pp
4314dc88ebeSGabor Kovesdan.Dl $ grep -v -e 'foo' -e 'bar' myfile
4324dc88ebeSGabor Kovesdan.Pp
4334dc88ebeSGabor KovesdanA simple example of an extended regular expression:
4344dc88ebeSGabor Kovesdan.Pp
4354dc88ebeSGabor Kovesdan.Dl $ egrep '19|20|25' calendar
4364dc88ebeSGabor Kovesdan.Pp
4374dc88ebeSGabor KovesdanPeruses the file
4384dc88ebeSGabor Kovesdan.Sq calendar
4394dc88ebeSGabor Kovesdanlooking for either 19, 20, or 25.
4404dc88ebeSGabor Kovesdan.Sh SEE ALSO
4414dc88ebeSGabor Kovesdan.Xr ed 1 ,
4424dc88ebeSGabor Kovesdan.Xr ex 1 ,
4434dc88ebeSGabor Kovesdan.Xr sed 1 ,
4444dc88ebeSGabor Kovesdan.Xr re_format 7
4454dc88ebeSGabor Kovesdan.Sh STANDARDS
4464dc88ebeSGabor KovesdanThe
4474dc88ebeSGabor Kovesdan.Nm
4484dc88ebeSGabor Kovesdanutility is compliant with the
4494dc88ebeSGabor Kovesdan.St -p1003.1-2008
4504dc88ebeSGabor Kovesdanspecification.
4514dc88ebeSGabor Kovesdan.Pp
4524dc88ebeSGabor KovesdanThe flags
4534dc88ebeSGabor Kovesdan.Op Fl AaBbCDdGHhIJLmoPRSUVwZ
4544dc88ebeSGabor Kovesdanare extensions to that specification, and the behaviour of the
4554dc88ebeSGabor Kovesdan.Fl f
4564dc88ebeSGabor Kovesdanflag when used with an empty pattern file is left undefined.
4574dc88ebeSGabor Kovesdan.Pp
4584dc88ebeSGabor KovesdanAll long options are provided for compatibility with
4594dc88ebeSGabor KovesdanGNU versions of this utility.
4604dc88ebeSGabor Kovesdan.Pp
4614dc88ebeSGabor KovesdanHistoric versions of the
4624dc88ebeSGabor Kovesdan.Nm grep
4634dc88ebeSGabor Kovesdanutility also supported the flags
4644dc88ebeSGabor Kovesdan.Op Fl ruy .
4654dc88ebeSGabor KovesdanThis implementation supports those options;
4664dc88ebeSGabor Kovesdanhowever, their use is strongly discouraged.
4674dc88ebeSGabor Kovesdan.Sh HISTORY
4684dc88ebeSGabor KovesdanThe
4694dc88ebeSGabor Kovesdan.Nm grep
4704dc88ebeSGabor Kovesdancommand first appeared in
4714dc88ebeSGabor Kovesdan.At v6 .
472