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*88d24183SGordon Bergling.Dd August 7, 2020 344dc88ebeSGabor Kovesdan.Dt GREP 1 354dc88ebeSGabor Kovesdan.Os 364dc88ebeSGabor Kovesdan.Sh NAME 376ddfef55SMateusz Piotrowski.Nm grep , 386ddfef55SMateusz Piotrowski.Nm egrep , 396ddfef55SMateusz Piotrowski.Nm fgrep , 406ddfef55SMateusz Piotrowski.Nm rgrep 414dc88ebeSGabor Kovesdan.Nd file pattern searcher 424dc88ebeSGabor Kovesdan.Sh SYNOPSIS 434dc88ebeSGabor Kovesdan.Nm grep 444dc88ebeSGabor Kovesdan.Bk -words 454a5b4207SBaptiste Daroussin.Op Fl abcdDEFGHhIiLlmnOopqRSsUVvwxz 464dc88ebeSGabor Kovesdan.Op Fl A Ar num 474dc88ebeSGabor Kovesdan.Op Fl B Ar num 484dc88ebeSGabor Kovesdan.Op Fl C Ns Op Ar num 494dc88ebeSGabor Kovesdan.Op Fl e Ar pattern 504dc88ebeSGabor Kovesdan.Op Fl f Ar file 516ddfef55SMateusz Piotrowski.Op Fl Fl binary-files= Ns Ar value 526ddfef55SMateusz Piotrowski.Op Fl Fl color Ns Op Cm = Ns Ar when 536ddfef55SMateusz Piotrowski.Op Fl Fl colour Ns Op Cm = Ns Ar when 546ddfef55SMateusz Piotrowski.Op Fl Fl context Ns Op Cm = Ns Ar num 554dc88ebeSGabor Kovesdan.Op Fl Fl label 564dc88ebeSGabor Kovesdan.Op Fl Fl line-buffered 574dc88ebeSGabor Kovesdan.Op Fl Fl null 584dc88ebeSGabor Kovesdan.Op Ar pattern 594dc88ebeSGabor Kovesdan.Op Ar 604dc88ebeSGabor Kovesdan.Ek 614dc88ebeSGabor Kovesdan.Sh DESCRIPTION 624dc88ebeSGabor KovesdanThe 634dc88ebeSGabor Kovesdan.Nm grep 644dc88ebeSGabor Kovesdanutility searches any given input files, 654dc88ebeSGabor Kovesdanselecting lines that match one or more patterns. 664dc88ebeSGabor KovesdanBy default, a pattern matches an input line if the regular expression 674dc88ebeSGabor Kovesdan(RE) in the pattern matches the input line 684dc88ebeSGabor Kovesdanwithout its trailing newline. 694dc88ebeSGabor KovesdanAn empty expression matches every line. 704dc88ebeSGabor KovesdanEach input line that matches at least one of the patterns is written 714dc88ebeSGabor Kovesdanto the standard output. 724dc88ebeSGabor Kovesdan.Pp 734dc88ebeSGabor Kovesdan.Nm grep 744dc88ebeSGabor Kovesdanis used for simple patterns and 754dc88ebeSGabor Kovesdanbasic regular expressions 764dc88ebeSGabor Kovesdan.Pq BREs ; 774dc88ebeSGabor Kovesdan.Nm egrep 784dc88ebeSGabor Kovesdancan handle extended regular expressions 794dc88ebeSGabor Kovesdan.Pq EREs . 804dc88ebeSGabor KovesdanSee 814dc88ebeSGabor Kovesdan.Xr re_format 7 824dc88ebeSGabor Kovesdanfor more information on regular expressions. 834dc88ebeSGabor Kovesdan.Nm fgrep 844dc88ebeSGabor Kovesdanis quicker than both 854dc88ebeSGabor Kovesdan.Nm grep 864dc88ebeSGabor Kovesdanand 874dc88ebeSGabor Kovesdan.Nm egrep , 884dc88ebeSGabor Kovesdanbut can only handle fixed patterns 896ddfef55SMateusz Piotrowski(i.e., it does not interpret regular expressions). 904dc88ebeSGabor KovesdanPatterns may consist of one or more lines, 914dc88ebeSGabor Kovesdanallowing any of the pattern lines to match a portion of the input. 924dc88ebeSGabor Kovesdan.Pp 934dc88ebeSGabor KovesdanThe following options are available: 944dc88ebeSGabor Kovesdan.Bl -tag -width indent 956ddfef55SMateusz Piotrowski.It Fl A Ar num , Fl Fl after-context= Ns Ar num 964dc88ebeSGabor KovesdanPrint 974dc88ebeSGabor Kovesdan.Ar num 984dc88ebeSGabor Kovesdanlines of trailing context after each match. 994dc88ebeSGabor KovesdanSee also the 1004dc88ebeSGabor Kovesdan.Fl B 1014dc88ebeSGabor Kovesdanand 1024dc88ebeSGabor Kovesdan.Fl C 1034dc88ebeSGabor Kovesdanoptions. 1044dc88ebeSGabor Kovesdan.It Fl a , Fl Fl text 1054dc88ebeSGabor KovesdanTreat all files as ASCII text. 1064dc88ebeSGabor KovesdanNormally 1074dc88ebeSGabor Kovesdan.Nm 1084dc88ebeSGabor Kovesdanwill simply print 1094dc88ebeSGabor Kovesdan.Dq Binary file ... matches 1104dc88ebeSGabor Kovesdanif files contain binary characters. 1114dc88ebeSGabor KovesdanUse of this option forces 1124dc88ebeSGabor Kovesdan.Nm 1134dc88ebeSGabor Kovesdanto output lines matching the specified pattern. 1146ddfef55SMateusz Piotrowski.It Fl B Ar num , Fl Fl before-context= Ns Ar num 1154dc88ebeSGabor KovesdanPrint 1164dc88ebeSGabor Kovesdan.Ar num 1174dc88ebeSGabor Kovesdanlines of leading context before each match. 1184dc88ebeSGabor KovesdanSee also the 1194dc88ebeSGabor Kovesdan.Fl A 1204dc88ebeSGabor Kovesdanand 1214dc88ebeSGabor Kovesdan.Fl C 1224dc88ebeSGabor Kovesdanoptions. 1234dc88ebeSGabor Kovesdan.It Fl b , Fl Fl byte-offset 1244dc88ebeSGabor KovesdanThe offset in bytes of a matched pattern is 1254dc88ebeSGabor Kovesdandisplayed in front of the respective matched line. 1266ddfef55SMateusz Piotrowski.It Fl C Ns Oo Ar num Oc , Fl Fl context Ns Oo = Ns Ar num Oc 1274dc88ebeSGabor KovesdanPrint 1284dc88ebeSGabor Kovesdan.Ar num 1294dc88ebeSGabor Kovesdanlines of leading and trailing context surrounding each match. 1306ddfef55SMateusz PiotrowskiThe default value of 1316ddfef55SMateusz Piotrowski.Ar num 1326ddfef55SMateusz Piotrowskiis 1336ddfef55SMateusz Piotrowski.Dq 2 1346ddfef55SMateusz Piotrowskiand is equivalent to 1356ddfef55SMateusz Piotrowski.Dq Fl A Ar 2 Fl B Ar 2 . 1364dc88ebeSGabor KovesdanNote: 1374dc88ebeSGabor Kovesdanno whitespace may be given between the option and its argument. 1384dc88ebeSGabor Kovesdan.It Fl c , Fl Fl count 1394dc88ebeSGabor KovesdanOnly a count of selected lines is written to standard output. 1406ddfef55SMateusz Piotrowski.It Fl Fl colour= Ns Oo Ar when Oc , Fl Fl color= Ns Oo Ar when Oc 1416ddfef55SMateusz PiotrowskiMark up the matching text with the expression stored in the 1424dc88ebeSGabor Kovesdan.Ev GREP_COLOR 1434dc88ebeSGabor Kovesdanenvironment variable. 1446ddfef55SMateusz PiotrowskiThe possible values of 1456ddfef55SMateusz Piotrowski.Ar when 1466ddfef55SMateusz Piotrowskiare 1476ddfef55SMateusz Piotrowski.Dq Cm never , 1486ddfef55SMateusz Piotrowski.Dq Cm always 1496ddfef55SMateusz Piotrowskiand 1506ddfef55SMateusz Piotrowski.Dq Cm auto . 1516ddfef55SMateusz Piotrowski.It Fl D Ar action , Fl Fl devices= Ns Ar action 1526ddfef55SMateusz PiotrowskiSpecify the demanded 1536ddfef55SMateusz Piotrowski.Ar action 1546ddfef55SMateusz Piotrowskifor devices, FIFOs and sockets. 1556ddfef55SMateusz PiotrowskiThe default 1566ddfef55SMateusz Piotrowski.Ar action 1576ddfef55SMateusz Piotrowskiis 1586ddfef55SMateusz Piotrowski.Dq Cm read , 1596ddfef55SMateusz Piotrowskiwhich means, that they are read as if they were normal files. 1606ddfef55SMateusz PiotrowskiIf the 1616ddfef55SMateusz Piotrowski.Ar action 1626ddfef55SMateusz Piotrowskiis set to 1636ddfef55SMateusz Piotrowski.Dq Cm skip , 1646ddfef55SMateusz Piotrowskidevices are silently skipped. 1656ddfef55SMateusz Piotrowski.It Fl d Ar action , Fl Fl directories= Ns Ar action 1666ddfef55SMateusz PiotrowskiSpecify the demanded 1676ddfef55SMateusz Piotrowski.Ar action 1686ddfef55SMateusz Piotrowskifor directories. 1696ddfef55SMateusz PiotrowskiIt is 1706ddfef55SMateusz Piotrowski.Dq Cm read 1716ddfef55SMateusz Piotrowskiby default, which means that the directories 1724dc88ebeSGabor Kovesdanare read in the same manner as normal files. 1736ddfef55SMateusz PiotrowskiOther possible values are 1746ddfef55SMateusz Piotrowski.Dq Cm skip 1756ddfef55SMateusz Piotrowskito silently ignore the directories, and 1766ddfef55SMateusz Piotrowski.Dq Cm recurse 1776ddfef55SMateusz Piotrowskito read them recursively, which has the same effect as the 1784dc88ebeSGabor Kovesdan.Fl R 1794dc88ebeSGabor Kovesdanand 1804dc88ebeSGabor Kovesdan.Fl r 1814dc88ebeSGabor Kovesdanoption. 1824dc88ebeSGabor Kovesdan.It Fl E , Fl Fl extended-regexp 1834dc88ebeSGabor KovesdanInterpret 1844dc88ebeSGabor Kovesdan.Ar pattern 1854dc88ebeSGabor Kovesdanas an extended regular expression 1866ddfef55SMateusz Piotrowski(i.e., force 1874dc88ebeSGabor Kovesdan.Nm grep 1884dc88ebeSGabor Kovesdanto behave as 1894dc88ebeSGabor Kovesdan.Nm egrep ) . 1906ddfef55SMateusz Piotrowski.It Fl e Ar pattern , Fl Fl regexp= Ns Ar pattern 1916ddfef55SMateusz PiotrowskiSpecify a 1926ddfef55SMateusz Piotrowski.Ar pattern 1936ddfef55SMateusz Piotrowskiused during the search of the input: 1944dc88ebeSGabor Kovesdanan input line is selected if it matches any of the specified patterns. 1954dc88ebeSGabor KovesdanThis option is most useful when multiple 1964dc88ebeSGabor Kovesdan.Fl e 1974dc88ebeSGabor Kovesdanoptions are used to specify multiple patterns, 1986ddfef55SMateusz Piotrowskior when a 1996ddfef55SMateusz Piotrowski.Ar pattern 2006ddfef55SMateusz Piotrowskibegins with a dash 2014dc88ebeSGabor Kovesdan.Pq Sq - . 2026ddfef55SMateusz Piotrowski.It Fl Fl exclude Ar pattern 20355e44f51SGabor KovesdanIf specified, it excludes files matching the given 2046ddfef55SMateusz Piotrowskifilename 2056ddfef55SMateusz Piotrowski.Ar pattern 2066ddfef55SMateusz Piotrowskifrom the search. 20755e44f51SGabor KovesdanNote that 20855e44f51SGabor Kovesdan.Fl Fl exclude 209bd509bdbSKyle Evansand 21055e44f51SGabor Kovesdan.Fl Fl include 211bd509bdbSKyle Evanspatterns are processed in the order given. 212*88d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 213bd509bdbSKyle EvansIf no 21455e44f51SGabor Kovesdan.Fl Fl include 21555e44f51SGabor Kovesdanpattern is specified, all files are searched that are 21655e44f51SGabor Kovesdannot excluded. 21755e44f51SGabor KovesdanPatterns are matched to the full path specified, 21855e44f51SGabor Kovesdannot only to the filename component. 2196ddfef55SMateusz Piotrowski.It Fl Fl exclude-dir Ar pattern 2204dc88ebeSGabor KovesdanIf 2214dc88ebeSGabor Kovesdan.Fl R 2224dc88ebeSGabor Kovesdanis specified, it excludes directories matching the 2236ddfef55SMateusz Piotrowskigiven filename 2246ddfef55SMateusz Piotrowski.Ar pattern 2256ddfef55SMateusz Piotrowskifrom the search. 22655e44f51SGabor KovesdanNote that 22755e44f51SGabor Kovesdan.Fl Fl exclude-dir 228bd509bdbSKyle Evansand 22955e44f51SGabor Kovesdan.Fl Fl include-dir 230bd509bdbSKyle Evanspatterns are processed in the order given. 231*88d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 232bd509bdbSKyle EvansIf no 23355e44f51SGabor Kovesdan.Fl Fl include-dir 23455e44f51SGabor Kovesdanpattern is specified, all directories are searched that are 23555e44f51SGabor Kovesdannot excluded. 2364dc88ebeSGabor Kovesdan.It Fl F , Fl Fl fixed-strings 2374dc88ebeSGabor KovesdanInterpret 2384dc88ebeSGabor Kovesdan.Ar pattern 2394dc88ebeSGabor Kovesdanas a set of fixed strings 2406ddfef55SMateusz Piotrowski(i.e., force 2414dc88ebeSGabor Kovesdan.Nm grep 2424dc88ebeSGabor Kovesdanto behave as 2434dc88ebeSGabor Kovesdan.Nm fgrep ) . 2446ddfef55SMateusz Piotrowski.It Fl f Ar file , Fl Fl file= Ns Ar file 2454dc88ebeSGabor KovesdanRead one or more newline separated patterns from 2464dc88ebeSGabor Kovesdan.Ar file . 2474dc88ebeSGabor KovesdanEmpty pattern lines match every input line. 2484dc88ebeSGabor KovesdanNewlines are not considered part of a pattern. 2494dc88ebeSGabor KovesdanIf 2504dc88ebeSGabor Kovesdan.Ar file 2514dc88ebeSGabor Kovesdanis empty, nothing is matched. 2524dc88ebeSGabor Kovesdan.It Fl G , Fl Fl basic-regexp 2534dc88ebeSGabor KovesdanInterpret 2544dc88ebeSGabor Kovesdan.Ar pattern 2554dc88ebeSGabor Kovesdanas a basic regular expression 2566ddfef55SMateusz Piotrowski(i.e., force 2574dc88ebeSGabor Kovesdan.Nm grep 2584dc88ebeSGabor Kovesdanto behave as traditional 2594dc88ebeSGabor Kovesdan.Nm grep ) . 2604dc88ebeSGabor Kovesdan.It Fl H 2614dc88ebeSGabor KovesdanAlways print filename headers with output lines. 2624dc88ebeSGabor Kovesdan.It Fl h , Fl Fl no-filename 2634dc88ebeSGabor KovesdanNever print filename headers 2646ddfef55SMateusz Piotrowski.Pq i.e., filenames 2654dc88ebeSGabor Kovesdanwith output lines. 2664dc88ebeSGabor Kovesdan.It Fl Fl help 2674dc88ebeSGabor KovesdanPrint a brief help message. 2684dc88ebeSGabor Kovesdan.It Fl I 2694dc88ebeSGabor KovesdanIgnore binary files. 2706ddfef55SMateusz PiotrowskiThis option is equivalent to the 2716ddfef55SMateusz Piotrowski.Dq Fl Fl binary-file= Ns Cm without-match 2724dc88ebeSGabor Kovesdanoption. 2734dc88ebeSGabor Kovesdan.It Fl i , Fl Fl ignore-case 2744dc88ebeSGabor KovesdanPerform case insensitive matching. 2754dc88ebeSGabor KovesdanBy default, 2764dc88ebeSGabor Kovesdan.Nm grep 2774dc88ebeSGabor Kovesdanis case sensitive. 2786ddfef55SMateusz Piotrowski.It Fl Fl include Ar pattern 2796ddfef55SMateusz PiotrowskiIf specified, only files matching the given filename 2806ddfef55SMateusz Piotrowski.Ar pattern 2816ddfef55SMateusz Piotrowskiare searched. 28255e44f51SGabor KovesdanNote that 28355e44f51SGabor Kovesdan.Fl Fl include 284bd509bdbSKyle Evansand 285bd509bdbSKyle Evans.Fl Fl exclude 286bd509bdbSKyle Evanspatterns are processed in the order given. 287*88d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 28855e44f51SGabor KovesdanPatterns are matched to the full path specified, 28955e44f51SGabor Kovesdannot only to the filename component. 2906ddfef55SMateusz Piotrowski.It Fl Fl include-dir Ar pattern 2914dc88ebeSGabor KovesdanIf 2924dc88ebeSGabor Kovesdan.Fl R 2936ddfef55SMateusz Piotrowskiis specified, only directories matching the given filename 2946ddfef55SMateusz Piotrowski.Ar pattern 2956ddfef55SMateusz Piotrowskiare searched. 29655e44f51SGabor KovesdanNote that 29755e44f51SGabor Kovesdan.Fl Fl include-dir 298bd509bdbSKyle Evansand 299bd509bdbSKyle Evans.Fl Fl exclude-dir 300bd509bdbSKyle Evanspatterns are processed in the order given. 301*88d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 3024dc88ebeSGabor Kovesdan.It Fl L , Fl Fl files-without-match 3034dc88ebeSGabor KovesdanOnly the names of files not containing selected lines are written to 3044dc88ebeSGabor Kovesdanstandard output. 3054dc88ebeSGabor KovesdanPathnames are listed once per file searched. 3064dc88ebeSGabor KovesdanIf the standard input is searched, the string 3074dc88ebeSGabor Kovesdan.Dq (standard input) 308bd509bdbSKyle Evansis written unless a 309bd509bdbSKyle Evans.Fl Fl label 310bd509bdbSKyle Evansis specified. 3114dc88ebeSGabor Kovesdan.It Fl l , Fl Fl files-with-matches 3124dc88ebeSGabor KovesdanOnly the names of files containing selected lines are written to 3134dc88ebeSGabor Kovesdanstandard output. 3144dc88ebeSGabor Kovesdan.Nm grep 3154dc88ebeSGabor Kovesdanwill only search a file until a match has been found, 3164dc88ebeSGabor Kovesdanmaking searches potentially less expensive. 3174dc88ebeSGabor KovesdanPathnames are listed once per file searched. 3184dc88ebeSGabor KovesdanIf the standard input is searched, the string 3194dc88ebeSGabor Kovesdan.Dq (standard input) 320bd509bdbSKyle Evansis written unless a 321bd509bdbSKyle Evans.Fl Fl label 322bd509bdbSKyle Evansis specified. 323bd509bdbSKyle Evans.It Fl Fl label 324bd509bdbSKyle EvansLabel to use in place of 325bd509bdbSKyle Evans.Dq (standard input) 326bd509bdbSKyle Evansfor a file name where a file name would normally be printed. 327bd509bdbSKyle EvansThis option applies to 328bd509bdbSKyle Evans.Fl H , 329bd509bdbSKyle Evans.Fl L , 330bd509bdbSKyle Evansand 331bd509bdbSKyle Evans.Fl l . 3324dc88ebeSGabor Kovesdan.It Fl Fl mmap 3334dc88ebeSGabor KovesdanUse 3344dc88ebeSGabor Kovesdan.Xr mmap 2 3354dc88ebeSGabor Kovesdaninstead of 3364dc88ebeSGabor Kovesdan.Xr read 2 3374dc88ebeSGabor Kovesdanto read input, which can result in better performance under some 338a4f5b3dfSJoel Dahlcircumstances but can cause undefined behaviour. 3396ddfef55SMateusz Piotrowski.It Fl m Ar num , Fl Fl max-count= Ns Ar num 3404dc88ebeSGabor KovesdanStop reading the file after 3414dc88ebeSGabor Kovesdan.Ar num 3424dc88ebeSGabor Kovesdanmatches. 3434dc88ebeSGabor Kovesdan.It Fl n , Fl Fl line-number 3444dc88ebeSGabor KovesdanEach output line is preceded by its relative line number in the file, 3454dc88ebeSGabor Kovesdanstarting at line 1. 3464dc88ebeSGabor KovesdanThe line number counter is reset for each file processed. 3474dc88ebeSGabor KovesdanThis option is ignored if 3484dc88ebeSGabor Kovesdan.Fl c , 3494dc88ebeSGabor Kovesdan.Fl L , 3504dc88ebeSGabor Kovesdan.Fl l , 3514dc88ebeSGabor Kovesdanor 3524dc88ebeSGabor Kovesdan.Fl q 3534dc88ebeSGabor Kovesdanis 3544dc88ebeSGabor Kovesdanspecified. 3554dc88ebeSGabor Kovesdan.It Fl Fl null 3564dc88ebeSGabor KovesdanPrints a zero-byte after the file name. 3574dc88ebeSGabor Kovesdan.It Fl O 3584dc88ebeSGabor KovesdanIf 3594dc88ebeSGabor Kovesdan.Fl R 3604dc88ebeSGabor Kovesdanis specified, follow symbolic links only if they were explicitly listed 3614dc88ebeSGabor Kovesdanon the command line. 3624dc88ebeSGabor KovesdanThe default is not to follow symbolic links. 3634dc88ebeSGabor Kovesdan.It Fl o , Fl Fl only-matching 3644dc88ebeSGabor KovesdanPrints only the matching part of the lines. 3654dc88ebeSGabor Kovesdan.It Fl p 3664dc88ebeSGabor KovesdanIf 3674dc88ebeSGabor Kovesdan.Fl R 3684dc88ebeSGabor Kovesdanis specified, no symbolic links are followed. 3694dc88ebeSGabor KovesdanThis is the default. 3704dc88ebeSGabor Kovesdan.It Fl q , Fl Fl quiet , Fl Fl silent 3714dc88ebeSGabor KovesdanQuiet mode: 3724dc88ebeSGabor Kovesdansuppress normal output. 3734dc88ebeSGabor Kovesdan.Nm grep 3744dc88ebeSGabor Kovesdanwill only search a file until a match has been found, 3754dc88ebeSGabor Kovesdanmaking searches potentially less expensive. 3764dc88ebeSGabor Kovesdan.It Fl R , Fl r , Fl Fl recursive 3774dc88ebeSGabor KovesdanRecursively search subdirectories listed. 3786ddfef55SMateusz Piotrowski(i.e., force 379bf10f246SConrad Meyer.Nm grep 380bf10f246SConrad Meyerto behave as 381bf10f246SConrad Meyer.Nm rgrep ) . 3824dc88ebeSGabor Kovesdan.It Fl S 3834dc88ebeSGabor KovesdanIf 3844dc88ebeSGabor Kovesdan.Fl R 3854dc88ebeSGabor Kovesdanis specified, all symbolic links are followed. 3864dc88ebeSGabor KovesdanThe default is not to follow symbolic links. 3874dc88ebeSGabor Kovesdan.It Fl s , Fl Fl no-messages 3884dc88ebeSGabor KovesdanSilent mode. 3894dc88ebeSGabor KovesdanNonexistent and unreadable files are ignored 3906ddfef55SMateusz Piotrowski(i.e., their error messages are suppressed). 3914dc88ebeSGabor Kovesdan.It Fl U , Fl Fl binary 3924dc88ebeSGabor KovesdanSearch binary files, but do not attempt to print them. 3936b91f517SEd Maste.It Fl u 3946b91f517SEd MasteThis option has no effect and is provided only for compatibility with GNU grep. 3954dc88ebeSGabor Kovesdan.It Fl V , Fl Fl version 3964dc88ebeSGabor KovesdanDisplay version information and exit. 3974dc88ebeSGabor Kovesdan.It Fl v , Fl Fl invert-match 3984dc88ebeSGabor KovesdanSelected lines are those 3994dc88ebeSGabor Kovesdan.Em not 4004dc88ebeSGabor Kovesdanmatching any of the specified patterns. 4014dc88ebeSGabor Kovesdan.It Fl w , Fl Fl word-regexp 4024dc88ebeSGabor KovesdanThe expression is searched for as a word (as if surrounded by 4034dc88ebeSGabor Kovesdan.Sq [[:<:]] 4044dc88ebeSGabor Kovesdanand 4054dc88ebeSGabor Kovesdan.Sq [[:>:]] ; 4064dc88ebeSGabor Kovesdansee 4074dc88ebeSGabor Kovesdan.Xr re_format 7 ) . 4084dc88ebeSGabor Kovesdan.It Fl x , Fl Fl line-regexp 4094dc88ebeSGabor KovesdanOnly input lines selected against an entire fixed string or regular 4104dc88ebeSGabor Kovesdanexpression are considered to be matching lines. 4114dc88ebeSGabor Kovesdan.It Fl y 4124dc88ebeSGabor KovesdanEquivalent to 4134dc88ebeSGabor Kovesdan.Fl i . 4144dc88ebeSGabor KovesdanObsoleted. 4155ee1ea02SEd Maste.It Fl z , Fl Fl null-data 4165ee1ea02SEd MasteTreat input and output data as sequences of lines terminated by a 4175ee1ea02SEd Mastezero-byte instead of a newline. 4186ddfef55SMateusz Piotrowski.It Fl Fl binary-files= Ns Ar value 4194dc88ebeSGabor KovesdanControls searching and printing of binary files. 4206ddfef55SMateusz PiotrowskiOptions are: 4216ddfef55SMateusz Piotrowski.Bl -tag -compact -width "binary (default)" 4226ddfef55SMateusz Piotrowski.It Cm binary No (default) 4236ddfef55SMateusz PiotrowskiSearch binary files but do not print them. 4246ddfef55SMateusz Piotrowski.It Cm without-match 4256ddfef55SMateusz PiotrowskiDo not search binary files. 4266ddfef55SMateusz Piotrowski.It Cm text 4276ddfef55SMateusz PiotrowskiTreat all files as text. 4286ddfef55SMateusz Piotrowski.El 4294dc88ebeSGabor Kovesdan.It Fl Fl line-buffered 4304dc88ebeSGabor KovesdanForce output to be line buffered. 4314dc88ebeSGabor KovesdanBy default, output is line buffered when standard output is a terminal 4324dc88ebeSGabor Kovesdanand block buffered otherwise. 4334dc88ebeSGabor Kovesdan.El 4347e700c30SJoel Dahl.Pp 4354dc88ebeSGabor KovesdanIf no file arguments are specified, the standard input is used. 43624a656c2SKyle EvansAdditionally, 4376ddfef55SMateusz Piotrowski.Dq Cm - 43824a656c2SKyle Evansmay be used in place of a file name, anywhere that a file name is accepted, to 43924a656c2SKyle Evansread from standard input. 44024a656c2SKyle EvansThis includes both 44124a656c2SKyle Evans.Fl f 44224a656c2SKyle Evansand file arguments. 443e9a67923SGabor Kovesdan.Sh EXIT STATUS 4444dc88ebeSGabor KovesdanThe 4454dc88ebeSGabor Kovesdan.Nm grep 4464dc88ebeSGabor Kovesdanutility exits with one of the following values: 4474dc88ebeSGabor Kovesdan.Pp 4484dc88ebeSGabor Kovesdan.Bl -tag -width flag -compact 4494dc88ebeSGabor Kovesdan.It Li 0 4504dc88ebeSGabor KovesdanOne or more lines were selected. 4514dc88ebeSGabor Kovesdan.It Li 1 4524dc88ebeSGabor KovesdanNo lines were selected. 4534dc88ebeSGabor Kovesdan.It Li \*(Gt1 4544dc88ebeSGabor KovesdanAn error occurred. 4554dc88ebeSGabor Kovesdan.El 4564dc88ebeSGabor Kovesdan.Sh EXAMPLES 4576ddfef55SMateusz Piotrowski.Bl -dash 4586ddfef55SMateusz Piotrowski.It 4594dc88ebeSGabor KovesdanTo find all occurrences of the word 4604dc88ebeSGabor Kovesdan.Sq patricia 4614dc88ebeSGabor Kovesdanin a file: 4624dc88ebeSGabor Kovesdan.Pp 4634dc88ebeSGabor Kovesdan.Dl $ grep 'patricia' myfile 4646ddfef55SMateusz Piotrowski.It 4654dc88ebeSGabor KovesdanTo find all occurrences of the pattern 4664dc88ebeSGabor Kovesdan.Ql .Pp 4674dc88ebeSGabor Kovesdanat the beginning of a line: 4684dc88ebeSGabor Kovesdan.Pp 4694dc88ebeSGabor Kovesdan.Dl $ grep '^\e.Pp' myfile 4704dc88ebeSGabor Kovesdan.Pp 4714dc88ebeSGabor KovesdanThe apostrophes ensure the entire expression is evaluated by 4724dc88ebeSGabor Kovesdan.Nm grep 4734dc88ebeSGabor Kovesdaninstead of by the user's shell. 4744dc88ebeSGabor KovesdanThe caret 4754dc88ebeSGabor Kovesdan.Ql ^ 4764dc88ebeSGabor Kovesdanmatches the null string at the beginning of a line, 4774dc88ebeSGabor Kovesdanand the 4784dc88ebeSGabor Kovesdan.Ql \e 4794dc88ebeSGabor Kovesdanescapes the 4804dc88ebeSGabor Kovesdan.Ql \&. , 4814dc88ebeSGabor Kovesdanwhich would otherwise match any character. 4826ddfef55SMateusz Piotrowski.It 4834dc88ebeSGabor KovesdanTo find all lines in a file which do not contain the words 4844dc88ebeSGabor Kovesdan.Sq foo 4854dc88ebeSGabor Kovesdanor 4864dc88ebeSGabor Kovesdan.Sq bar : 4874dc88ebeSGabor Kovesdan.Pp 4884dc88ebeSGabor Kovesdan.Dl $ grep -v -e 'foo' -e 'bar' myfile 4896ddfef55SMateusz Piotrowski.It 4904dc88ebeSGabor KovesdanA simple example of an extended regular expression: 4914dc88ebeSGabor Kovesdan.Pp 4924dc88ebeSGabor Kovesdan.Dl $ egrep '19|20|25' calendar 4934dc88ebeSGabor Kovesdan.Pp 4944dc88ebeSGabor KovesdanPeruses the file 4954dc88ebeSGabor Kovesdan.Sq calendar 4964dc88ebeSGabor Kovesdanlooking for either 19, 20, or 25. 4976ddfef55SMateusz Piotrowski.El 4984dc88ebeSGabor Kovesdan.Sh SEE ALSO 4994dc88ebeSGabor Kovesdan.Xr ed 1 , 5004dc88ebeSGabor Kovesdan.Xr ex 1 , 5014dc88ebeSGabor Kovesdan.Xr sed 1 , 5026ddfef55SMateusz Piotrowski.Xr zgrep 1 , 5034dc88ebeSGabor Kovesdan.Xr re_format 7 5044dc88ebeSGabor Kovesdan.Sh STANDARDS 5054dc88ebeSGabor KovesdanThe 5064dc88ebeSGabor Kovesdan.Nm 5074dc88ebeSGabor Kovesdanutility is compliant with the 5084dc88ebeSGabor Kovesdan.St -p1003.1-2008 5094dc88ebeSGabor Kovesdanspecification. 5104dc88ebeSGabor Kovesdan.Pp 5114dc88ebeSGabor KovesdanThe flags 512bd509bdbSKyle Evans.Op Fl AaBbCDdGHhILmoPRSUVw 5134dc88ebeSGabor Kovesdanare extensions to that specification, and the behaviour of the 5144dc88ebeSGabor Kovesdan.Fl f 5154dc88ebeSGabor Kovesdanflag when used with an empty pattern file is left undefined. 5164dc88ebeSGabor Kovesdan.Pp 5174dc88ebeSGabor KovesdanAll long options are provided for compatibility with 5184dc88ebeSGabor KovesdanGNU versions of this utility. 5194dc88ebeSGabor Kovesdan.Pp 5204dc88ebeSGabor KovesdanHistoric versions of the 5214dc88ebeSGabor Kovesdan.Nm grep 5224dc88ebeSGabor Kovesdanutility also supported the flags 5234dc88ebeSGabor Kovesdan.Op Fl ruy . 5244dc88ebeSGabor KovesdanThis implementation supports those options; 5254dc88ebeSGabor Kovesdanhowever, their use is strongly discouraged. 5264dc88ebeSGabor Kovesdan.Sh HISTORY 5274dc88ebeSGabor KovesdanThe 5284dc88ebeSGabor Kovesdan.Nm grep 5294dc88ebeSGabor Kovesdancommand first appeared in 5304dc88ebeSGabor Kovesdan.At v6 . 531