1b66a823bSGabor Kovesdan.\" $NetBSD: grep.1,v 1.2 2011/02/16 01:31:33 joerg Exp $ 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.\" 30*cf7fe60eSJose Luis Duran.Dd December 18, 2022 314dc88ebeSGabor Kovesdan.Dt GREP 1 324dc88ebeSGabor Kovesdan.Os 334dc88ebeSGabor Kovesdan.Sh NAME 346ddfef55SMateusz Piotrowski.Nm grep , 356ddfef55SMateusz Piotrowski.Nm egrep , 366ddfef55SMateusz Piotrowski.Nm fgrep , 376ddfef55SMateusz Piotrowski.Nm rgrep 384dc88ebeSGabor Kovesdan.Nd file pattern searcher 394dc88ebeSGabor Kovesdan.Sh SYNOPSIS 404dc88ebeSGabor Kovesdan.Nm grep 414dc88ebeSGabor Kovesdan.Bk -words 424a5b4207SBaptiste Daroussin.Op Fl abcdDEFGHhIiLlmnOopqRSsUVvwxz 434dc88ebeSGabor Kovesdan.Op Fl A Ar num 444dc88ebeSGabor Kovesdan.Op Fl B Ar num 45be6b8b7aSMateusz Piotrowski.Op Fl C Ar num 464dc88ebeSGabor Kovesdan.Op Fl e Ar pattern 474dc88ebeSGabor Kovesdan.Op Fl f Ar file 486ddfef55SMateusz Piotrowski.Op Fl Fl binary-files= Ns Ar value 496ddfef55SMateusz Piotrowski.Op Fl Fl color Ns Op Cm = Ns Ar when 506ddfef55SMateusz Piotrowski.Op Fl Fl colour Ns Op Cm = Ns Ar when 51be6b8b7aSMateusz Piotrowski.Op Fl Fl context= 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 866ddfef55SMateusz Piotrowski(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 926ddfef55SMateusz Piotrowski.It Fl A Ar num , Fl Fl after-context= 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. 1116ddfef55SMateusz Piotrowski.It Fl B Ar num , Fl Fl before-context= 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. 123be6b8b7aSMateusz Piotrowski.It Fl C Ar num , Fl Fl context= Ns Ar num 1244dc88ebeSGabor KovesdanPrint 1254dc88ebeSGabor Kovesdan.Ar num 1264dc88ebeSGabor Kovesdanlines of leading and trailing context surrounding each match. 127be6b8b7aSMateusz PiotrowskiSee also the 128be6b8b7aSMateusz Piotrowski.Fl A 129be6b8b7aSMateusz Piotrowskiand 130be6b8b7aSMateusz Piotrowski.Fl B 131be6b8b7aSMateusz Piotrowskioptions. 1324dc88ebeSGabor Kovesdan.It Fl c , Fl Fl count 1334dc88ebeSGabor KovesdanOnly a count of selected lines is written to standard output. 1346ddfef55SMateusz Piotrowski.It Fl Fl colour= Ns Oo Ar when Oc , Fl Fl color= Ns Oo Ar when Oc 1356ddfef55SMateusz PiotrowskiMark up the matching text with the expression stored in the 1364dc88ebeSGabor Kovesdan.Ev GREP_COLOR 1374dc88ebeSGabor Kovesdanenvironment variable. 1386ddfef55SMateusz PiotrowskiThe possible values of 1396ddfef55SMateusz Piotrowski.Ar when 1406ddfef55SMateusz Piotrowskiare 1416ddfef55SMateusz Piotrowski.Dq Cm never , 1426ddfef55SMateusz Piotrowski.Dq Cm always 1436ddfef55SMateusz Piotrowskiand 1446ddfef55SMateusz Piotrowski.Dq Cm auto . 1456ddfef55SMateusz Piotrowski.It Fl D Ar action , Fl Fl devices= Ns Ar action 1466ddfef55SMateusz PiotrowskiSpecify the demanded 1476ddfef55SMateusz Piotrowski.Ar action 1486ddfef55SMateusz Piotrowskifor devices, FIFOs and sockets. 1496ddfef55SMateusz PiotrowskiThe default 1506ddfef55SMateusz Piotrowski.Ar action 1516ddfef55SMateusz Piotrowskiis 1526ddfef55SMateusz Piotrowski.Dq Cm read , 1536ddfef55SMateusz Piotrowskiwhich means, that they are read as if they were normal files. 1546ddfef55SMateusz PiotrowskiIf the 1556ddfef55SMateusz Piotrowski.Ar action 1566ddfef55SMateusz Piotrowskiis set to 1576ddfef55SMateusz Piotrowski.Dq Cm skip , 1586ddfef55SMateusz Piotrowskidevices are silently skipped. 1596ddfef55SMateusz Piotrowski.It Fl d Ar action , Fl Fl directories= Ns Ar action 1606ddfef55SMateusz PiotrowskiSpecify the demanded 1616ddfef55SMateusz Piotrowski.Ar action 1626ddfef55SMateusz Piotrowskifor directories. 1636ddfef55SMateusz PiotrowskiIt is 1646ddfef55SMateusz Piotrowski.Dq Cm read 1656ddfef55SMateusz Piotrowskiby default, which means that the directories 1664dc88ebeSGabor Kovesdanare read in the same manner as normal files. 1676ddfef55SMateusz PiotrowskiOther possible values are 1686ddfef55SMateusz Piotrowski.Dq Cm skip 1696ddfef55SMateusz Piotrowskito silently ignore the directories, and 1706ddfef55SMateusz Piotrowski.Dq Cm recurse 1716ddfef55SMateusz Piotrowskito read them recursively, which has the same effect as the 1724dc88ebeSGabor Kovesdan.Fl R 1734dc88ebeSGabor Kovesdanand 1744dc88ebeSGabor Kovesdan.Fl r 1754dc88ebeSGabor Kovesdanoption. 1764dc88ebeSGabor Kovesdan.It Fl E , Fl Fl extended-regexp 1774dc88ebeSGabor KovesdanInterpret 1784dc88ebeSGabor Kovesdan.Ar pattern 1794dc88ebeSGabor Kovesdanas an extended regular expression 1806ddfef55SMateusz Piotrowski(i.e., force 1814dc88ebeSGabor Kovesdan.Nm grep 1824dc88ebeSGabor Kovesdanto behave as 1834dc88ebeSGabor Kovesdan.Nm egrep ) . 1846ddfef55SMateusz Piotrowski.It Fl e Ar pattern , Fl Fl regexp= Ns Ar pattern 1856ddfef55SMateusz PiotrowskiSpecify a 1866ddfef55SMateusz Piotrowski.Ar pattern 1876ddfef55SMateusz Piotrowskiused during the search of the input: 1884dc88ebeSGabor Kovesdanan input line is selected if it matches any of the specified patterns. 1894dc88ebeSGabor KovesdanThis option is most useful when multiple 1904dc88ebeSGabor Kovesdan.Fl e 1914dc88ebeSGabor Kovesdanoptions are used to specify multiple patterns, 1926ddfef55SMateusz Piotrowskior when a 1936ddfef55SMateusz Piotrowski.Ar pattern 1946ddfef55SMateusz Piotrowskibegins with a dash 1954dc88ebeSGabor Kovesdan.Pq Sq - . 1966ddfef55SMateusz Piotrowski.It Fl Fl exclude Ar pattern 19755e44f51SGabor KovesdanIf specified, it excludes files matching the given 1986ddfef55SMateusz Piotrowskifilename 1996ddfef55SMateusz Piotrowski.Ar pattern 2006ddfef55SMateusz Piotrowskifrom the search. 20155e44f51SGabor KovesdanNote that 20255e44f51SGabor Kovesdan.Fl Fl exclude 203bd509bdbSKyle Evansand 20455e44f51SGabor Kovesdan.Fl Fl include 205bd509bdbSKyle Evanspatterns are processed in the order given. 20688d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 207bd509bdbSKyle EvansIf no 20855e44f51SGabor Kovesdan.Fl Fl include 20955e44f51SGabor Kovesdanpattern is specified, all files are searched that are 21055e44f51SGabor Kovesdannot excluded. 21155e44f51SGabor KovesdanPatterns are matched to the full path specified, 21255e44f51SGabor Kovesdannot only to the filename component. 2136ddfef55SMateusz Piotrowski.It Fl Fl exclude-dir Ar pattern 2144dc88ebeSGabor KovesdanIf 2154dc88ebeSGabor Kovesdan.Fl R 2164dc88ebeSGabor Kovesdanis specified, it excludes directories matching the 2176ddfef55SMateusz Piotrowskigiven filename 2186ddfef55SMateusz Piotrowski.Ar pattern 2196ddfef55SMateusz Piotrowskifrom the search. 22055e44f51SGabor KovesdanNote that 22155e44f51SGabor Kovesdan.Fl Fl exclude-dir 222bd509bdbSKyle Evansand 22355e44f51SGabor Kovesdan.Fl Fl include-dir 224bd509bdbSKyle Evanspatterns are processed in the order given. 22588d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 226bd509bdbSKyle EvansIf no 22755e44f51SGabor Kovesdan.Fl Fl include-dir 22855e44f51SGabor Kovesdanpattern is specified, all directories are searched that are 22955e44f51SGabor Kovesdannot excluded. 2304dc88ebeSGabor Kovesdan.It Fl F , Fl Fl fixed-strings 2314dc88ebeSGabor KovesdanInterpret 2324dc88ebeSGabor Kovesdan.Ar pattern 2334dc88ebeSGabor Kovesdanas a set of fixed strings 2346ddfef55SMateusz Piotrowski(i.e., force 2354dc88ebeSGabor Kovesdan.Nm grep 2364dc88ebeSGabor Kovesdanto behave as 2374dc88ebeSGabor Kovesdan.Nm fgrep ) . 2386ddfef55SMateusz Piotrowski.It Fl f Ar file , Fl Fl file= Ns Ar file 2394dc88ebeSGabor KovesdanRead one or more newline separated patterns from 2404dc88ebeSGabor Kovesdan.Ar file . 2414dc88ebeSGabor KovesdanEmpty pattern lines match every input line. 2424dc88ebeSGabor KovesdanNewlines are not considered part of a pattern. 2434dc88ebeSGabor KovesdanIf 2444dc88ebeSGabor Kovesdan.Ar file 2454dc88ebeSGabor Kovesdanis empty, nothing is matched. 2464dc88ebeSGabor Kovesdan.It Fl G , Fl Fl basic-regexp 2474dc88ebeSGabor KovesdanInterpret 2484dc88ebeSGabor Kovesdan.Ar pattern 2494dc88ebeSGabor Kovesdanas a basic regular expression 2506ddfef55SMateusz Piotrowski(i.e., force 2514dc88ebeSGabor Kovesdan.Nm grep 2524dc88ebeSGabor Kovesdanto behave as traditional 2534dc88ebeSGabor Kovesdan.Nm grep ) . 2544dc88ebeSGabor Kovesdan.It Fl H 2554dc88ebeSGabor KovesdanAlways print filename headers with output lines. 2564dc88ebeSGabor Kovesdan.It Fl h , Fl Fl no-filename 2574dc88ebeSGabor KovesdanNever print filename headers 2586ddfef55SMateusz Piotrowski.Pq i.e., filenames 2594dc88ebeSGabor Kovesdanwith output lines. 2604dc88ebeSGabor Kovesdan.It Fl Fl help 2614dc88ebeSGabor KovesdanPrint a brief help message. 2624dc88ebeSGabor Kovesdan.It Fl I 2634dc88ebeSGabor KovesdanIgnore binary files. 2646ddfef55SMateusz PiotrowskiThis option is equivalent to the 265085a42d0SElvin Aslanov.Dq Fl Fl binary-files= Ns Cm without-match 2664dc88ebeSGabor Kovesdanoption. 2674dc88ebeSGabor Kovesdan.It Fl i , Fl Fl ignore-case 2684dc88ebeSGabor KovesdanPerform case insensitive matching. 2694dc88ebeSGabor KovesdanBy default, 2704dc88ebeSGabor Kovesdan.Nm grep 2714dc88ebeSGabor Kovesdanis case sensitive. 2726ddfef55SMateusz Piotrowski.It Fl Fl include Ar pattern 2736ddfef55SMateusz PiotrowskiIf specified, only files matching the given filename 2746ddfef55SMateusz Piotrowski.Ar pattern 2756ddfef55SMateusz Piotrowskiare searched. 27655e44f51SGabor KovesdanNote that 27755e44f51SGabor Kovesdan.Fl Fl include 278bd509bdbSKyle Evansand 279bd509bdbSKyle Evans.Fl Fl exclude 280bd509bdbSKyle Evanspatterns are processed in the order given. 28188d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 28255e44f51SGabor KovesdanPatterns are matched to the full path specified, 28355e44f51SGabor Kovesdannot only to the filename component. 2846ddfef55SMateusz Piotrowski.It Fl Fl include-dir Ar pattern 2854dc88ebeSGabor KovesdanIf 2864dc88ebeSGabor Kovesdan.Fl R 2876ddfef55SMateusz Piotrowskiis specified, only directories matching the given filename 2886ddfef55SMateusz Piotrowski.Ar pattern 2896ddfef55SMateusz Piotrowskiare searched. 29055e44f51SGabor KovesdanNote that 29155e44f51SGabor Kovesdan.Fl Fl include-dir 292bd509bdbSKyle Evansand 293bd509bdbSKyle Evans.Fl Fl exclude-dir 294bd509bdbSKyle Evanspatterns are processed in the order given. 29588d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 2964dc88ebeSGabor Kovesdan.It Fl L , Fl Fl files-without-match 2974dc88ebeSGabor KovesdanOnly the names of files not containing selected lines are written to 2984dc88ebeSGabor Kovesdanstandard output. 2994dc88ebeSGabor KovesdanPathnames are listed once per file searched. 3004dc88ebeSGabor KovesdanIf the standard input is searched, the string 3014dc88ebeSGabor Kovesdan.Dq (standard input) 302bd509bdbSKyle Evansis written unless a 303bd509bdbSKyle Evans.Fl Fl label 304bd509bdbSKyle Evansis specified. 3054dc88ebeSGabor Kovesdan.It Fl l , Fl Fl files-with-matches 3064dc88ebeSGabor KovesdanOnly the names of files containing selected lines are written to 3074dc88ebeSGabor Kovesdanstandard output. 3084dc88ebeSGabor Kovesdan.Nm grep 3094dc88ebeSGabor Kovesdanwill only search a file until a match has been found, 3104dc88ebeSGabor Kovesdanmaking searches potentially less expensive. 3114dc88ebeSGabor KovesdanPathnames are listed once per file searched. 3124dc88ebeSGabor KovesdanIf the standard input is searched, the string 3134dc88ebeSGabor Kovesdan.Dq (standard input) 314bd509bdbSKyle Evansis written unless a 315bd509bdbSKyle Evans.Fl Fl label 316bd509bdbSKyle Evansis specified. 317bd509bdbSKyle Evans.It Fl Fl label 318bd509bdbSKyle EvansLabel to use in place of 319bd509bdbSKyle Evans.Dq (standard input) 320bd509bdbSKyle Evansfor a file name where a file name would normally be printed. 321bd509bdbSKyle EvansThis option applies to 322bd509bdbSKyle Evans.Fl H , 323bd509bdbSKyle Evans.Fl L , 324bd509bdbSKyle Evansand 325bd509bdbSKyle Evans.Fl l . 3264dc88ebeSGabor Kovesdan.It Fl Fl mmap 3274dc88ebeSGabor KovesdanUse 3284dc88ebeSGabor Kovesdan.Xr mmap 2 3294dc88ebeSGabor Kovesdaninstead of 3304dc88ebeSGabor Kovesdan.Xr read 2 3314dc88ebeSGabor Kovesdanto read input, which can result in better performance under some 332a4f5b3dfSJoel Dahlcircumstances but can cause undefined behaviour. 3336ddfef55SMateusz Piotrowski.It Fl m Ar num , Fl Fl max-count= Ns Ar num 3344dc88ebeSGabor KovesdanStop reading the file after 3354dc88ebeSGabor Kovesdan.Ar num 3364dc88ebeSGabor Kovesdanmatches. 3374dc88ebeSGabor Kovesdan.It Fl n , Fl Fl line-number 3384dc88ebeSGabor KovesdanEach output line is preceded by its relative line number in the file, 3394dc88ebeSGabor Kovesdanstarting at line 1. 3404dc88ebeSGabor KovesdanThe line number counter is reset for each file processed. 3414dc88ebeSGabor KovesdanThis option is ignored if 3424dc88ebeSGabor Kovesdan.Fl c , 3434dc88ebeSGabor Kovesdan.Fl L , 3444dc88ebeSGabor Kovesdan.Fl l , 3454dc88ebeSGabor Kovesdanor 3464dc88ebeSGabor Kovesdan.Fl q 3474dc88ebeSGabor Kovesdanis 3484dc88ebeSGabor Kovesdanspecified. 3494dc88ebeSGabor Kovesdan.It Fl Fl null 3504dc88ebeSGabor KovesdanPrints a zero-byte after the file name. 3514dc88ebeSGabor Kovesdan.It Fl O 3524dc88ebeSGabor KovesdanIf 3534dc88ebeSGabor Kovesdan.Fl R 3544dc88ebeSGabor Kovesdanis specified, follow symbolic links only if they were explicitly listed 3554dc88ebeSGabor Kovesdanon the command line. 3564dc88ebeSGabor KovesdanThe default is not to follow symbolic links. 3574dc88ebeSGabor Kovesdan.It Fl o , Fl Fl only-matching 3584dc88ebeSGabor KovesdanPrints only the matching part of the lines. 3594dc88ebeSGabor Kovesdan.It Fl p 3604dc88ebeSGabor KovesdanIf 3614dc88ebeSGabor Kovesdan.Fl R 3624dc88ebeSGabor Kovesdanis specified, no symbolic links are followed. 3634dc88ebeSGabor KovesdanThis is the default. 3644dc88ebeSGabor Kovesdan.It Fl q , Fl Fl quiet , Fl Fl silent 3654dc88ebeSGabor KovesdanQuiet mode: 3664dc88ebeSGabor Kovesdansuppress normal output. 3674dc88ebeSGabor Kovesdan.Nm grep 3684dc88ebeSGabor Kovesdanwill only search a file until a match has been found, 3694dc88ebeSGabor Kovesdanmaking searches potentially less expensive. 3704dc88ebeSGabor Kovesdan.It Fl R , Fl r , Fl Fl recursive 3714dc88ebeSGabor KovesdanRecursively search subdirectories listed. 3726ddfef55SMateusz Piotrowski(i.e., force 373bf10f246SConrad Meyer.Nm grep 374bf10f246SConrad Meyerto behave as 375bf10f246SConrad Meyer.Nm rgrep ) . 3764dc88ebeSGabor Kovesdan.It Fl S 3774dc88ebeSGabor KovesdanIf 3784dc88ebeSGabor Kovesdan.Fl R 3794dc88ebeSGabor Kovesdanis specified, all symbolic links are followed. 3804dc88ebeSGabor KovesdanThe default is not to follow symbolic links. 3814dc88ebeSGabor Kovesdan.It Fl s , Fl Fl no-messages 3824dc88ebeSGabor KovesdanSilent mode. 3834dc88ebeSGabor KovesdanNonexistent and unreadable files are ignored 3846ddfef55SMateusz Piotrowski(i.e., their error messages are suppressed). 3854dc88ebeSGabor Kovesdan.It Fl U , Fl Fl binary 3864dc88ebeSGabor KovesdanSearch binary files, but do not attempt to print them. 3876b91f517SEd Maste.It Fl u 3886b91f517SEd MasteThis option has no effect and is provided only for compatibility with GNU grep. 3894dc88ebeSGabor Kovesdan.It Fl V , Fl Fl version 3904dc88ebeSGabor KovesdanDisplay version information and exit. 3914dc88ebeSGabor Kovesdan.It Fl v , Fl Fl invert-match 3924dc88ebeSGabor KovesdanSelected lines are those 3934dc88ebeSGabor Kovesdan.Em not 3944dc88ebeSGabor Kovesdanmatching any of the specified patterns. 3954dc88ebeSGabor Kovesdan.It Fl w , Fl Fl word-regexp 3964dc88ebeSGabor KovesdanThe expression is searched for as a word (as if surrounded by 3974dc88ebeSGabor Kovesdan.Sq [[:<:]] 3984dc88ebeSGabor Kovesdanand 3994dc88ebeSGabor Kovesdan.Sq [[:>:]] ; 4004dc88ebeSGabor Kovesdansee 4014dc88ebeSGabor Kovesdan.Xr re_format 7 ) . 4022373acbbSKyle EvansThis option has no effect if 4032373acbbSKyle Evans.Fl x 4042373acbbSKyle Evansis also specified. 4054dc88ebeSGabor Kovesdan.It Fl x , Fl Fl line-regexp 4064dc88ebeSGabor KovesdanOnly input lines selected against an entire fixed string or regular 4074dc88ebeSGabor Kovesdanexpression are considered to be matching lines. 4084dc88ebeSGabor Kovesdan.It Fl y 4094dc88ebeSGabor KovesdanEquivalent to 4104dc88ebeSGabor Kovesdan.Fl i . 4114dc88ebeSGabor KovesdanObsoleted. 4125ee1ea02SEd Maste.It Fl z , Fl Fl null-data 4135ee1ea02SEd MasteTreat input and output data as sequences of lines terminated by a 4145ee1ea02SEd Mastezero-byte instead of a newline. 4156ddfef55SMateusz Piotrowski.It Fl Fl binary-files= Ns Ar value 4164dc88ebeSGabor KovesdanControls searching and printing of binary files. 4176ddfef55SMateusz PiotrowskiOptions are: 4186ddfef55SMateusz Piotrowski.Bl -tag -compact -width "binary (default)" 4196ddfef55SMateusz Piotrowski.It Cm binary No (default) 4206ddfef55SMateusz PiotrowskiSearch binary files but do not print them. 4216ddfef55SMateusz Piotrowski.It Cm without-match 4226ddfef55SMateusz PiotrowskiDo not search binary files. 4236ddfef55SMateusz Piotrowski.It Cm text 4246ddfef55SMateusz PiotrowskiTreat all files as text. 4256ddfef55SMateusz Piotrowski.El 4264dc88ebeSGabor Kovesdan.It Fl Fl line-buffered 4274dc88ebeSGabor KovesdanForce output to be line buffered. 4284dc88ebeSGabor KovesdanBy default, output is line buffered when standard output is a terminal 4294dc88ebeSGabor Kovesdanand block buffered otherwise. 4304dc88ebeSGabor Kovesdan.El 4317e700c30SJoel Dahl.Pp 4324dc88ebeSGabor KovesdanIf no file arguments are specified, the standard input is used. 43324a656c2SKyle EvansAdditionally, 4346ddfef55SMateusz Piotrowski.Dq Cm - 43524a656c2SKyle Evansmay be used in place of a file name, anywhere that a file name is accepted, to 43624a656c2SKyle Evansread from standard input. 43724a656c2SKyle EvansThis includes both 43824a656c2SKyle Evans.Fl f 43924a656c2SKyle Evansand file arguments. 440*cf7fe60eSJose Luis Duran.Sh ENVIRONMENT 441*cf7fe60eSJose Luis DuranThe following environment variables affect the execution of 442*cf7fe60eSJose Luis Duran.Nm : 443*cf7fe60eSJose Luis Duran.Bl -tag -width "GREP_OPTIONS" 444*cf7fe60eSJose Luis Duran.It Ev GREP_COLOR 445*cf7fe60eSJose Luis DuranThis variable specifies the color used to highlight matched (non-empty) text. 446*cf7fe60eSJose Luis Duran.It Ev GREP_OPTIONS 447*cf7fe60eSJose Luis DuranThis variable specifies default options 448*cf7fe60eSJose Luis Duranto be placed in front of any explicit options. 449*cf7fe60eSJose Luis DuranIt may cause problems with portable scripts. 450*cf7fe60eSJose Luis Duran.It Ev TERM 451*cf7fe60eSJose Luis DuranThis variable specifies the type name of the terminal, console or display-device 452*cf7fe60eSJose Luis Durantype to be used. 453*cf7fe60eSJose Luis DuranSee 454*cf7fe60eSJose Luis Duran.Xr term 7 . 455*cf7fe60eSJose Luis Duran.El 456e9a67923SGabor Kovesdan.Sh EXIT STATUS 4574dc88ebeSGabor KovesdanThe 4584dc88ebeSGabor Kovesdan.Nm grep 4594dc88ebeSGabor Kovesdanutility exits with one of the following values: 4604dc88ebeSGabor Kovesdan.Pp 4614dc88ebeSGabor Kovesdan.Bl -tag -width flag -compact 4624dc88ebeSGabor Kovesdan.It Li 0 4634dc88ebeSGabor KovesdanOne or more lines were selected. 4644dc88ebeSGabor Kovesdan.It Li 1 4654dc88ebeSGabor KovesdanNo lines were selected. 4664dc88ebeSGabor Kovesdan.It Li \*(Gt1 4674dc88ebeSGabor KovesdanAn error occurred. 4684dc88ebeSGabor Kovesdan.El 4694dc88ebeSGabor Kovesdan.Sh EXAMPLES 4706ddfef55SMateusz Piotrowski.Bl -dash 4716ddfef55SMateusz Piotrowski.It 4725be3f744SFernando ApesteguíaFind all occurrences of the pattern 4734dc88ebeSGabor Kovesdan.Sq patricia 4744dc88ebeSGabor Kovesdanin a file: 4754dc88ebeSGabor Kovesdan.Pp 4764dc88ebeSGabor Kovesdan.Dl $ grep 'patricia' myfile 4776ddfef55SMateusz Piotrowski.It 4785be3f744SFernando ApesteguíaSame as above but looking only for complete words: 4795be3f744SFernando Apesteguía.Pp 4805be3f744SFernando Apesteguía.Dl $ grep -w 'patricia' myfile 4815be3f744SFernando Apesteguía.It 4825be3f744SFernando ApesteguíaCount occurrences of the exact pattern 4835be3f744SFernando Apesteguía.Sq FOO 4845be3f744SFernando Apesteguía: 4855be3f744SFernando Apesteguía.Pp 4865be3f744SFernando Apesteguía.Dl $ grep -c FOO myfile 4875be3f744SFernando Apesteguía.It 4885be3f744SFernando ApesteguíaSame as above but ignoring case: 4895be3f744SFernando Apesteguía.Pp 4905be3f744SFernando Apesteguía.Dl $ grep -c -i FOO myfile 4915be3f744SFernando Apesteguía.It 4925be3f744SFernando ApesteguíaFind all occurrences of the pattern 4934dc88ebeSGabor Kovesdan.Ql .Pp 4944dc88ebeSGabor Kovesdanat the beginning of a line: 4954dc88ebeSGabor Kovesdan.Pp 4964dc88ebeSGabor Kovesdan.Dl $ grep '^\e.Pp' myfile 4974dc88ebeSGabor Kovesdan.Pp 4984dc88ebeSGabor KovesdanThe apostrophes ensure the entire expression is evaluated by 4994dc88ebeSGabor Kovesdan.Nm grep 5004dc88ebeSGabor Kovesdaninstead of by the user's shell. 5014dc88ebeSGabor KovesdanThe caret 5024dc88ebeSGabor Kovesdan.Ql ^ 5034dc88ebeSGabor Kovesdanmatches the null string at the beginning of a line, 5044dc88ebeSGabor Kovesdanand the 5054dc88ebeSGabor Kovesdan.Ql \e 5064dc88ebeSGabor Kovesdanescapes the 5074dc88ebeSGabor Kovesdan.Ql \&. , 5084dc88ebeSGabor Kovesdanwhich would otherwise match any character. 5096ddfef55SMateusz Piotrowski.It 5105be3f744SFernando ApesteguíaFind all lines in a file which do not contain the words 5114dc88ebeSGabor Kovesdan.Sq foo 5124dc88ebeSGabor Kovesdanor 5134dc88ebeSGabor Kovesdan.Sq bar : 5144dc88ebeSGabor Kovesdan.Pp 5154dc88ebeSGabor Kovesdan.Dl $ grep -v -e 'foo' -e 'bar' myfile 5166ddfef55SMateusz Piotrowski.It 5175be3f744SFernando ApesteguíaPeruse the file 5185be3f744SFernando Apesteguía.Sq calendar 5195be3f744SFernando Apesteguíalooking for either 19, 20, or 25 using extended regular expressions: 5204dc88ebeSGabor Kovesdan.Pp 5214dc88ebeSGabor Kovesdan.Dl $ egrep '19|20|25' calendar 5225be3f744SFernando Apesteguía.It 5235be3f744SFernando ApesteguíaShow matching lines and the name of the 5245be3f744SFernando Apesteguía.Sq *.h 5255be3f744SFernando Apesteguíafiles which contain the pattern 5265be3f744SFernando Apesteguía.Sq FIXME . 5275be3f744SFernando ApesteguíaDo the search recursively from the 5285be3f744SFernando Apesteguía.Pa /usr/src/sys/arm 5295be3f744SFernando Apesteguíadirectory 5304dc88ebeSGabor Kovesdan.Pp 531070e8d36SDaniel Engberg.Dl $ grep -H -R FIXME --include="*.h" /usr/src/sys/arm/ 5325be3f744SFernando Apesteguía.It 5335be3f744SFernando ApesteguíaSame as above but show only the name of the matching file: 5345be3f744SFernando Apesteguía.Pp 535070e8d36SDaniel Engberg.Dl $ grep -l -R FIXME --include="*.h" /usr/src/sys/arm/ 5365be3f744SFernando Apesteguía.It 5375be3f744SFernando ApesteguíaShow lines containing the text 5385be3f744SFernando Apesteguía.Sq foo . 5395be3f744SFernando ApesteguíaThe matching part of the output is colored and every line is prefixed with 5405be3f744SFernando Apesteguíathe line number and the offset in the file for those lines that matched. 5415be3f744SFernando Apesteguía.Pp 5425be3f744SFernando Apesteguía.Dl $ grep -b --colour -n foo myfile 5435be3f744SFernando Apesteguía.It 5445be3f744SFernando ApesteguíaShow lines that match the extended regular expression patterns read from the 5455be3f744SFernando Apesteguíastandard input: 5465be3f744SFernando Apesteguía.Pp 5475be3f744SFernando Apesteguía.Dl $ echo -e 'Free\enBSD\enAll.*reserved' | grep -E -f - myfile 5485be3f744SFernando Apesteguía.It 5495be3f744SFernando ApesteguíaShow lines from the output of the 5505be3f744SFernando Apesteguía.Xr pciconf 8 5515be3f744SFernando Apesteguíacommand matching the specified extended regular expression along with 5525be3f744SFernando Apesteguíathree lines of leading context and one line of trailing context: 5535be3f744SFernando Apesteguía.Pp 5545be3f744SFernando Apesteguía.Dl $ pciconf -lv | grep -B3 -A1 -E 'class.*=.*storage' 5555be3f744SFernando Apesteguía.It 5565be3f744SFernando ApesteguíaSuppress any output and use the exit status to show an appropriate message: 5575be3f744SFernando Apesteguía.Pp 5585be3f744SFernando Apesteguía.Dl $ grep -q foo myfile && echo File matches 5596ddfef55SMateusz Piotrowski.El 5604dc88ebeSGabor Kovesdan.Sh SEE ALSO 5614dc88ebeSGabor Kovesdan.Xr ed 1 , 5624dc88ebeSGabor Kovesdan.Xr ex 1 , 5634dc88ebeSGabor Kovesdan.Xr sed 1 , 5646ddfef55SMateusz Piotrowski.Xr zgrep 1 , 5654dc88ebeSGabor Kovesdan.Xr re_format 7 5664dc88ebeSGabor Kovesdan.Sh STANDARDS 5674dc88ebeSGabor KovesdanThe 5684dc88ebeSGabor Kovesdan.Nm 5694dc88ebeSGabor Kovesdanutility is compliant with the 5704dc88ebeSGabor Kovesdan.St -p1003.1-2008 5714dc88ebeSGabor Kovesdanspecification. 5724dc88ebeSGabor Kovesdan.Pp 5734dc88ebeSGabor KovesdanThe flags 5744c14980bSKyle Evans.Op Fl AaBbCDdGHhILmopRSUVw 5754dc88ebeSGabor Kovesdanare extensions to that specification, and the behaviour of the 5764dc88ebeSGabor Kovesdan.Fl f 5774dc88ebeSGabor Kovesdanflag when used with an empty pattern file is left undefined. 5784dc88ebeSGabor Kovesdan.Pp 5794dc88ebeSGabor KovesdanAll long options are provided for compatibility with 5804dc88ebeSGabor KovesdanGNU versions of this utility. 5814dc88ebeSGabor Kovesdan.Pp 5824dc88ebeSGabor KovesdanHistoric versions of the 5834dc88ebeSGabor Kovesdan.Nm grep 5844dc88ebeSGabor Kovesdanutility also supported the flags 5854dc88ebeSGabor Kovesdan.Op Fl ruy . 5864dc88ebeSGabor KovesdanThis implementation supports those options; 5874dc88ebeSGabor Kovesdanhowever, their use is strongly discouraged. 5884dc88ebeSGabor Kovesdan.Sh HISTORY 5894dc88ebeSGabor KovesdanThe 5904dc88ebeSGabor Kovesdan.Nm grep 5914dc88ebeSGabor Kovesdancommand first appeared in 5924dc88ebeSGabor Kovesdan.At v6 . 593