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*4c14980bSKyle Evans.Dd November 10, 2021 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 48be6b8b7aSMateusz Piotrowski.Op Fl C 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 54be6b8b7aSMateusz Piotrowski.Op Fl Fl context= 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. 126be6b8b7aSMateusz Piotrowski.It Fl C Ar num , Fl Fl context= Ns Ar num 1274dc88ebeSGabor KovesdanPrint 1284dc88ebeSGabor Kovesdan.Ar num 1294dc88ebeSGabor Kovesdanlines of leading and trailing context surrounding each match. 130be6b8b7aSMateusz PiotrowskiSee also the 131be6b8b7aSMateusz Piotrowski.Fl A 132be6b8b7aSMateusz Piotrowskiand 133be6b8b7aSMateusz Piotrowski.Fl B 134be6b8b7aSMateusz Piotrowskioptions. 1354dc88ebeSGabor Kovesdan.It Fl c , Fl Fl count 1364dc88ebeSGabor KovesdanOnly a count of selected lines is written to standard output. 1376ddfef55SMateusz Piotrowski.It Fl Fl colour= Ns Oo Ar when Oc , Fl Fl color= Ns Oo Ar when Oc 1386ddfef55SMateusz PiotrowskiMark up the matching text with the expression stored in the 1394dc88ebeSGabor Kovesdan.Ev GREP_COLOR 1404dc88ebeSGabor Kovesdanenvironment variable. 1416ddfef55SMateusz PiotrowskiThe possible values of 1426ddfef55SMateusz Piotrowski.Ar when 1436ddfef55SMateusz Piotrowskiare 1446ddfef55SMateusz Piotrowski.Dq Cm never , 1456ddfef55SMateusz Piotrowski.Dq Cm always 1466ddfef55SMateusz Piotrowskiand 1476ddfef55SMateusz Piotrowski.Dq Cm auto . 1486ddfef55SMateusz Piotrowski.It Fl D Ar action , Fl Fl devices= Ns Ar action 1496ddfef55SMateusz PiotrowskiSpecify the demanded 1506ddfef55SMateusz Piotrowski.Ar action 1516ddfef55SMateusz Piotrowskifor devices, FIFOs and sockets. 1526ddfef55SMateusz PiotrowskiThe default 1536ddfef55SMateusz Piotrowski.Ar action 1546ddfef55SMateusz Piotrowskiis 1556ddfef55SMateusz Piotrowski.Dq Cm read , 1566ddfef55SMateusz Piotrowskiwhich means, that they are read as if they were normal files. 1576ddfef55SMateusz PiotrowskiIf the 1586ddfef55SMateusz Piotrowski.Ar action 1596ddfef55SMateusz Piotrowskiis set to 1606ddfef55SMateusz Piotrowski.Dq Cm skip , 1616ddfef55SMateusz Piotrowskidevices are silently skipped. 1626ddfef55SMateusz Piotrowski.It Fl d Ar action , Fl Fl directories= Ns Ar action 1636ddfef55SMateusz PiotrowskiSpecify the demanded 1646ddfef55SMateusz Piotrowski.Ar action 1656ddfef55SMateusz Piotrowskifor directories. 1666ddfef55SMateusz PiotrowskiIt is 1676ddfef55SMateusz Piotrowski.Dq Cm read 1686ddfef55SMateusz Piotrowskiby default, which means that the directories 1694dc88ebeSGabor Kovesdanare read in the same manner as normal files. 1706ddfef55SMateusz PiotrowskiOther possible values are 1716ddfef55SMateusz Piotrowski.Dq Cm skip 1726ddfef55SMateusz Piotrowskito silently ignore the directories, and 1736ddfef55SMateusz Piotrowski.Dq Cm recurse 1746ddfef55SMateusz Piotrowskito read them recursively, which has the same effect as the 1754dc88ebeSGabor Kovesdan.Fl R 1764dc88ebeSGabor Kovesdanand 1774dc88ebeSGabor Kovesdan.Fl r 1784dc88ebeSGabor Kovesdanoption. 1794dc88ebeSGabor Kovesdan.It Fl E , Fl Fl extended-regexp 1804dc88ebeSGabor KovesdanInterpret 1814dc88ebeSGabor Kovesdan.Ar pattern 1824dc88ebeSGabor Kovesdanas an extended regular expression 1836ddfef55SMateusz Piotrowski(i.e., force 1844dc88ebeSGabor Kovesdan.Nm grep 1854dc88ebeSGabor Kovesdanto behave as 1864dc88ebeSGabor Kovesdan.Nm egrep ) . 1876ddfef55SMateusz Piotrowski.It Fl e Ar pattern , Fl Fl regexp= Ns Ar pattern 1886ddfef55SMateusz PiotrowskiSpecify a 1896ddfef55SMateusz Piotrowski.Ar pattern 1906ddfef55SMateusz Piotrowskiused during the search of the input: 1914dc88ebeSGabor Kovesdanan input line is selected if it matches any of the specified patterns. 1924dc88ebeSGabor KovesdanThis option is most useful when multiple 1934dc88ebeSGabor Kovesdan.Fl e 1944dc88ebeSGabor Kovesdanoptions are used to specify multiple patterns, 1956ddfef55SMateusz Piotrowskior when a 1966ddfef55SMateusz Piotrowski.Ar pattern 1976ddfef55SMateusz Piotrowskibegins with a dash 1984dc88ebeSGabor Kovesdan.Pq Sq - . 1996ddfef55SMateusz Piotrowski.It Fl Fl exclude Ar pattern 20055e44f51SGabor KovesdanIf specified, it excludes files matching the given 2016ddfef55SMateusz Piotrowskifilename 2026ddfef55SMateusz Piotrowski.Ar pattern 2036ddfef55SMateusz Piotrowskifrom the search. 20455e44f51SGabor KovesdanNote that 20555e44f51SGabor Kovesdan.Fl Fl exclude 206bd509bdbSKyle Evansand 20755e44f51SGabor Kovesdan.Fl Fl include 208bd509bdbSKyle Evanspatterns are processed in the order given. 20988d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 210bd509bdbSKyle EvansIf no 21155e44f51SGabor Kovesdan.Fl Fl include 21255e44f51SGabor Kovesdanpattern is specified, all files are searched that are 21355e44f51SGabor Kovesdannot excluded. 21455e44f51SGabor KovesdanPatterns are matched to the full path specified, 21555e44f51SGabor Kovesdannot only to the filename component. 2166ddfef55SMateusz Piotrowski.It Fl Fl exclude-dir Ar pattern 2174dc88ebeSGabor KovesdanIf 2184dc88ebeSGabor Kovesdan.Fl R 2194dc88ebeSGabor Kovesdanis specified, it excludes directories matching the 2206ddfef55SMateusz Piotrowskigiven filename 2216ddfef55SMateusz Piotrowski.Ar pattern 2226ddfef55SMateusz Piotrowskifrom the search. 22355e44f51SGabor KovesdanNote that 22455e44f51SGabor Kovesdan.Fl Fl exclude-dir 225bd509bdbSKyle Evansand 22655e44f51SGabor Kovesdan.Fl Fl include-dir 227bd509bdbSKyle Evanspatterns are processed in the order given. 22888d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 229bd509bdbSKyle EvansIf no 23055e44f51SGabor Kovesdan.Fl Fl include-dir 23155e44f51SGabor Kovesdanpattern is specified, all directories are searched that are 23255e44f51SGabor Kovesdannot excluded. 2334dc88ebeSGabor Kovesdan.It Fl F , Fl Fl fixed-strings 2344dc88ebeSGabor KovesdanInterpret 2354dc88ebeSGabor Kovesdan.Ar pattern 2364dc88ebeSGabor Kovesdanas a set of fixed strings 2376ddfef55SMateusz Piotrowski(i.e., force 2384dc88ebeSGabor Kovesdan.Nm grep 2394dc88ebeSGabor Kovesdanto behave as 2404dc88ebeSGabor Kovesdan.Nm fgrep ) . 2416ddfef55SMateusz Piotrowski.It Fl f Ar file , Fl Fl file= Ns Ar file 2424dc88ebeSGabor KovesdanRead one or more newline separated patterns from 2434dc88ebeSGabor Kovesdan.Ar file . 2444dc88ebeSGabor KovesdanEmpty pattern lines match every input line. 2454dc88ebeSGabor KovesdanNewlines are not considered part of a pattern. 2464dc88ebeSGabor KovesdanIf 2474dc88ebeSGabor Kovesdan.Ar file 2484dc88ebeSGabor Kovesdanis empty, nothing is matched. 2494dc88ebeSGabor Kovesdan.It Fl G , Fl Fl basic-regexp 2504dc88ebeSGabor KovesdanInterpret 2514dc88ebeSGabor Kovesdan.Ar pattern 2524dc88ebeSGabor Kovesdanas a basic regular expression 2536ddfef55SMateusz Piotrowski(i.e., force 2544dc88ebeSGabor Kovesdan.Nm grep 2554dc88ebeSGabor Kovesdanto behave as traditional 2564dc88ebeSGabor Kovesdan.Nm grep ) . 2574dc88ebeSGabor Kovesdan.It Fl H 2584dc88ebeSGabor KovesdanAlways print filename headers with output lines. 2594dc88ebeSGabor Kovesdan.It Fl h , Fl Fl no-filename 2604dc88ebeSGabor KovesdanNever print filename headers 2616ddfef55SMateusz Piotrowski.Pq i.e., filenames 2624dc88ebeSGabor Kovesdanwith output lines. 2634dc88ebeSGabor Kovesdan.It Fl Fl help 2644dc88ebeSGabor KovesdanPrint a brief help message. 2654dc88ebeSGabor Kovesdan.It Fl I 2664dc88ebeSGabor KovesdanIgnore binary files. 2676ddfef55SMateusz PiotrowskiThis option is equivalent to the 2686ddfef55SMateusz Piotrowski.Dq Fl Fl binary-file= Ns Cm without-match 2694dc88ebeSGabor Kovesdanoption. 2704dc88ebeSGabor Kovesdan.It Fl i , Fl Fl ignore-case 2714dc88ebeSGabor KovesdanPerform case insensitive matching. 2724dc88ebeSGabor KovesdanBy default, 2734dc88ebeSGabor Kovesdan.Nm grep 2744dc88ebeSGabor Kovesdanis case sensitive. 2756ddfef55SMateusz Piotrowski.It Fl Fl include Ar pattern 2766ddfef55SMateusz PiotrowskiIf specified, only files matching the given filename 2776ddfef55SMateusz Piotrowski.Ar pattern 2786ddfef55SMateusz Piotrowskiare searched. 27955e44f51SGabor KovesdanNote that 28055e44f51SGabor Kovesdan.Fl Fl include 281bd509bdbSKyle Evansand 282bd509bdbSKyle Evans.Fl Fl exclude 283bd509bdbSKyle Evanspatterns are processed in the order given. 28488d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 28555e44f51SGabor KovesdanPatterns are matched to the full path specified, 28655e44f51SGabor Kovesdannot only to the filename component. 2876ddfef55SMateusz Piotrowski.It Fl Fl include-dir Ar pattern 2884dc88ebeSGabor KovesdanIf 2894dc88ebeSGabor Kovesdan.Fl R 2906ddfef55SMateusz Piotrowskiis specified, only directories matching the given filename 2916ddfef55SMateusz Piotrowski.Ar pattern 2926ddfef55SMateusz Piotrowskiare searched. 29355e44f51SGabor KovesdanNote that 29455e44f51SGabor Kovesdan.Fl Fl include-dir 295bd509bdbSKyle Evansand 296bd509bdbSKyle Evans.Fl Fl exclude-dir 297bd509bdbSKyle Evanspatterns are processed in the order given. 29888d24183SGordon BerglingIf a name matches multiple patterns, the latest matching rule wins. 2994dc88ebeSGabor Kovesdan.It Fl L , Fl Fl files-without-match 3004dc88ebeSGabor KovesdanOnly the names of files not containing selected lines are written to 3014dc88ebeSGabor Kovesdanstandard output. 3024dc88ebeSGabor KovesdanPathnames are listed once per file searched. 3034dc88ebeSGabor KovesdanIf the standard input is searched, the string 3044dc88ebeSGabor Kovesdan.Dq (standard input) 305bd509bdbSKyle Evansis written unless a 306bd509bdbSKyle Evans.Fl Fl label 307bd509bdbSKyle Evansis specified. 3084dc88ebeSGabor Kovesdan.It Fl l , Fl Fl files-with-matches 3094dc88ebeSGabor KovesdanOnly the names of files containing selected lines are written to 3104dc88ebeSGabor Kovesdanstandard output. 3114dc88ebeSGabor Kovesdan.Nm grep 3124dc88ebeSGabor Kovesdanwill only search a file until a match has been found, 3134dc88ebeSGabor Kovesdanmaking searches potentially less expensive. 3144dc88ebeSGabor KovesdanPathnames are listed once per file searched. 3154dc88ebeSGabor KovesdanIf the standard input is searched, the string 3164dc88ebeSGabor Kovesdan.Dq (standard input) 317bd509bdbSKyle Evansis written unless a 318bd509bdbSKyle Evans.Fl Fl label 319bd509bdbSKyle Evansis specified. 320bd509bdbSKyle Evans.It Fl Fl label 321bd509bdbSKyle EvansLabel to use in place of 322bd509bdbSKyle Evans.Dq (standard input) 323bd509bdbSKyle Evansfor a file name where a file name would normally be printed. 324bd509bdbSKyle EvansThis option applies to 325bd509bdbSKyle Evans.Fl H , 326bd509bdbSKyle Evans.Fl L , 327bd509bdbSKyle Evansand 328bd509bdbSKyle Evans.Fl l . 3294dc88ebeSGabor Kovesdan.It Fl Fl mmap 3304dc88ebeSGabor KovesdanUse 3314dc88ebeSGabor Kovesdan.Xr mmap 2 3324dc88ebeSGabor Kovesdaninstead of 3334dc88ebeSGabor Kovesdan.Xr read 2 3344dc88ebeSGabor Kovesdanto read input, which can result in better performance under some 335a4f5b3dfSJoel Dahlcircumstances but can cause undefined behaviour. 3366ddfef55SMateusz Piotrowski.It Fl m Ar num , Fl Fl max-count= Ns Ar num 3374dc88ebeSGabor KovesdanStop reading the file after 3384dc88ebeSGabor Kovesdan.Ar num 3394dc88ebeSGabor Kovesdanmatches. 3404dc88ebeSGabor Kovesdan.It Fl n , Fl Fl line-number 3414dc88ebeSGabor KovesdanEach output line is preceded by its relative line number in the file, 3424dc88ebeSGabor Kovesdanstarting at line 1. 3434dc88ebeSGabor KovesdanThe line number counter is reset for each file processed. 3444dc88ebeSGabor KovesdanThis option is ignored if 3454dc88ebeSGabor Kovesdan.Fl c , 3464dc88ebeSGabor Kovesdan.Fl L , 3474dc88ebeSGabor Kovesdan.Fl l , 3484dc88ebeSGabor Kovesdanor 3494dc88ebeSGabor Kovesdan.Fl q 3504dc88ebeSGabor Kovesdanis 3514dc88ebeSGabor Kovesdanspecified. 3524dc88ebeSGabor Kovesdan.It Fl Fl null 3534dc88ebeSGabor KovesdanPrints a zero-byte after the file name. 3544dc88ebeSGabor Kovesdan.It Fl O 3554dc88ebeSGabor KovesdanIf 3564dc88ebeSGabor Kovesdan.Fl R 3574dc88ebeSGabor Kovesdanis specified, follow symbolic links only if they were explicitly listed 3584dc88ebeSGabor Kovesdanon the command line. 3594dc88ebeSGabor KovesdanThe default is not to follow symbolic links. 3604dc88ebeSGabor Kovesdan.It Fl o , Fl Fl only-matching 3614dc88ebeSGabor KovesdanPrints only the matching part of the lines. 3624dc88ebeSGabor Kovesdan.It Fl p 3634dc88ebeSGabor KovesdanIf 3644dc88ebeSGabor Kovesdan.Fl R 3654dc88ebeSGabor Kovesdanis specified, no symbolic links are followed. 3664dc88ebeSGabor KovesdanThis is the default. 3674dc88ebeSGabor Kovesdan.It Fl q , Fl Fl quiet , Fl Fl silent 3684dc88ebeSGabor KovesdanQuiet mode: 3694dc88ebeSGabor Kovesdansuppress normal output. 3704dc88ebeSGabor Kovesdan.Nm grep 3714dc88ebeSGabor Kovesdanwill only search a file until a match has been found, 3724dc88ebeSGabor Kovesdanmaking searches potentially less expensive. 3734dc88ebeSGabor Kovesdan.It Fl R , Fl r , Fl Fl recursive 3744dc88ebeSGabor KovesdanRecursively search subdirectories listed. 3756ddfef55SMateusz Piotrowski(i.e., force 376bf10f246SConrad Meyer.Nm grep 377bf10f246SConrad Meyerto behave as 378bf10f246SConrad Meyer.Nm rgrep ) . 3794dc88ebeSGabor Kovesdan.It Fl S 3804dc88ebeSGabor KovesdanIf 3814dc88ebeSGabor Kovesdan.Fl R 3824dc88ebeSGabor Kovesdanis specified, all symbolic links are followed. 3834dc88ebeSGabor KovesdanThe default is not to follow symbolic links. 3844dc88ebeSGabor Kovesdan.It Fl s , Fl Fl no-messages 3854dc88ebeSGabor KovesdanSilent mode. 3864dc88ebeSGabor KovesdanNonexistent and unreadable files are ignored 3876ddfef55SMateusz Piotrowski(i.e., their error messages are suppressed). 3884dc88ebeSGabor Kovesdan.It Fl U , Fl Fl binary 3894dc88ebeSGabor KovesdanSearch binary files, but do not attempt to print them. 3906b91f517SEd Maste.It Fl u 3916b91f517SEd MasteThis option has no effect and is provided only for compatibility with GNU grep. 3924dc88ebeSGabor Kovesdan.It Fl V , Fl Fl version 3934dc88ebeSGabor KovesdanDisplay version information and exit. 3944dc88ebeSGabor Kovesdan.It Fl v , Fl Fl invert-match 3954dc88ebeSGabor KovesdanSelected lines are those 3964dc88ebeSGabor Kovesdan.Em not 3974dc88ebeSGabor Kovesdanmatching any of the specified patterns. 3984dc88ebeSGabor Kovesdan.It Fl w , Fl Fl word-regexp 3994dc88ebeSGabor KovesdanThe expression is searched for as a word (as if surrounded by 4004dc88ebeSGabor Kovesdan.Sq [[:<:]] 4014dc88ebeSGabor Kovesdanand 4024dc88ebeSGabor Kovesdan.Sq [[:>:]] ; 4034dc88ebeSGabor Kovesdansee 4044dc88ebeSGabor Kovesdan.Xr re_format 7 ) . 4052373acbbSKyle EvansThis option has no effect if 4062373acbbSKyle Evans.Fl x 4072373acbbSKyle Evansis also specified. 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 4595be3f744SFernando ApesteguíaFind all occurrences of the pattern 4604dc88ebeSGabor Kovesdan.Sq patricia 4614dc88ebeSGabor Kovesdanin a file: 4624dc88ebeSGabor Kovesdan.Pp 4634dc88ebeSGabor Kovesdan.Dl $ grep 'patricia' myfile 4646ddfef55SMateusz Piotrowski.It 4655be3f744SFernando ApesteguíaSame as above but looking only for complete words: 4665be3f744SFernando Apesteguía.Pp 4675be3f744SFernando Apesteguía.Dl $ grep -w 'patricia' myfile 4685be3f744SFernando Apesteguía.It 4695be3f744SFernando ApesteguíaCount occurrences of the exact pattern 4705be3f744SFernando Apesteguía.Sq FOO 4715be3f744SFernando Apesteguía: 4725be3f744SFernando Apesteguía.Pp 4735be3f744SFernando Apesteguía.Dl $ grep -c FOO myfile 4745be3f744SFernando Apesteguía.It 4755be3f744SFernando ApesteguíaSame as above but ignoring case: 4765be3f744SFernando Apesteguía.Pp 4775be3f744SFernando Apesteguía.Dl $ grep -c -i FOO myfile 4785be3f744SFernando Apesteguía.It 4795be3f744SFernando ApesteguíaFind all occurrences of the pattern 4804dc88ebeSGabor Kovesdan.Ql .Pp 4814dc88ebeSGabor Kovesdanat the beginning of a line: 4824dc88ebeSGabor Kovesdan.Pp 4834dc88ebeSGabor Kovesdan.Dl $ grep '^\e.Pp' myfile 4844dc88ebeSGabor Kovesdan.Pp 4854dc88ebeSGabor KovesdanThe apostrophes ensure the entire expression is evaluated by 4864dc88ebeSGabor Kovesdan.Nm grep 4874dc88ebeSGabor Kovesdaninstead of by the user's shell. 4884dc88ebeSGabor KovesdanThe caret 4894dc88ebeSGabor Kovesdan.Ql ^ 4904dc88ebeSGabor Kovesdanmatches the null string at the beginning of a line, 4914dc88ebeSGabor Kovesdanand the 4924dc88ebeSGabor Kovesdan.Ql \e 4934dc88ebeSGabor Kovesdanescapes the 4944dc88ebeSGabor Kovesdan.Ql \&. , 4954dc88ebeSGabor Kovesdanwhich would otherwise match any character. 4966ddfef55SMateusz Piotrowski.It 4975be3f744SFernando ApesteguíaFind all lines in a file which do not contain the words 4984dc88ebeSGabor Kovesdan.Sq foo 4994dc88ebeSGabor Kovesdanor 5004dc88ebeSGabor Kovesdan.Sq bar : 5014dc88ebeSGabor Kovesdan.Pp 5024dc88ebeSGabor Kovesdan.Dl $ grep -v -e 'foo' -e 'bar' myfile 5036ddfef55SMateusz Piotrowski.It 5045be3f744SFernando ApesteguíaPeruse the file 5055be3f744SFernando Apesteguía.Sq calendar 5065be3f744SFernando Apesteguíalooking for either 19, 20, or 25 using extended regular expressions: 5074dc88ebeSGabor Kovesdan.Pp 5084dc88ebeSGabor Kovesdan.Dl $ egrep '19|20|25' calendar 5095be3f744SFernando Apesteguía.It 5105be3f744SFernando ApesteguíaShow matching lines and the name of the 5115be3f744SFernando Apesteguía.Sq *.h 5125be3f744SFernando Apesteguíafiles which contain the pattern 5135be3f744SFernando Apesteguía.Sq FIXME . 5145be3f744SFernando ApesteguíaDo the search recursively from the 5155be3f744SFernando Apesteguía.Pa /usr/src/sys/arm 5165be3f744SFernando Apesteguíadirectory 5174dc88ebeSGabor Kovesdan.Pp 5185be3f744SFernando Apesteguía.Dl $ grep -H -R FIXME --include=*.h /usr/src/sys/arm/ 5195be3f744SFernando Apesteguía.It 5205be3f744SFernando ApesteguíaSame as above but show only the name of the matching file: 5215be3f744SFernando Apesteguía.Pp 5225be3f744SFernando Apesteguía.Dl $ grep -l -R FIXME --include=*.h /usr/src/sys/arm/ 5235be3f744SFernando Apesteguía.It 5245be3f744SFernando ApesteguíaShow lines containing the text 5255be3f744SFernando Apesteguía.Sq foo . 5265be3f744SFernando ApesteguíaThe matching part of the output is colored and every line is prefixed with 5275be3f744SFernando Apesteguíathe line number and the offset in the file for those lines that matched. 5285be3f744SFernando Apesteguía.Pp 5295be3f744SFernando Apesteguía.Dl $ grep -b --colour -n foo myfile 5305be3f744SFernando Apesteguía.It 5315be3f744SFernando ApesteguíaShow lines that match the extended regular expression patterns read from the 5325be3f744SFernando Apesteguíastandard input: 5335be3f744SFernando Apesteguía.Pp 5345be3f744SFernando Apesteguía.Dl $ echo -e 'Free\enBSD\enAll.*reserved' | grep -E -f - myfile 5355be3f744SFernando Apesteguía.It 5365be3f744SFernando ApesteguíaShow lines from the output of the 5375be3f744SFernando Apesteguía.Xr pciconf 8 5385be3f744SFernando Apesteguíacommand matching the specified extended regular expression along with 5395be3f744SFernando Apesteguíathree lines of leading context and one line of trailing context: 5405be3f744SFernando Apesteguía.Pp 5415be3f744SFernando Apesteguía.Dl $ pciconf -lv | grep -B3 -A1 -E 'class.*=.*storage' 5425be3f744SFernando Apesteguía.It 5435be3f744SFernando ApesteguíaSuppress any output and use the exit status to show an appropriate message: 5445be3f744SFernando Apesteguía.Pp 5455be3f744SFernando Apesteguía.Dl $ grep -q foo myfile && echo File matches 5466ddfef55SMateusz Piotrowski.El 5474dc88ebeSGabor Kovesdan.Sh SEE ALSO 5484dc88ebeSGabor Kovesdan.Xr ed 1 , 5494dc88ebeSGabor Kovesdan.Xr ex 1 , 5504dc88ebeSGabor Kovesdan.Xr sed 1 , 5516ddfef55SMateusz Piotrowski.Xr zgrep 1 , 5524dc88ebeSGabor Kovesdan.Xr re_format 7 5534dc88ebeSGabor Kovesdan.Sh STANDARDS 5544dc88ebeSGabor KovesdanThe 5554dc88ebeSGabor Kovesdan.Nm 5564dc88ebeSGabor Kovesdanutility is compliant with the 5574dc88ebeSGabor Kovesdan.St -p1003.1-2008 5584dc88ebeSGabor Kovesdanspecification. 5594dc88ebeSGabor Kovesdan.Pp 5604dc88ebeSGabor KovesdanThe flags 561*4c14980bSKyle Evans.Op Fl AaBbCDdGHhILmopRSUVw 5624dc88ebeSGabor Kovesdanare extensions to that specification, and the behaviour of the 5634dc88ebeSGabor Kovesdan.Fl f 5644dc88ebeSGabor Kovesdanflag when used with an empty pattern file is left undefined. 5654dc88ebeSGabor Kovesdan.Pp 5664dc88ebeSGabor KovesdanAll long options are provided for compatibility with 5674dc88ebeSGabor KovesdanGNU versions of this utility. 5684dc88ebeSGabor Kovesdan.Pp 5694dc88ebeSGabor KovesdanHistoric versions of the 5704dc88ebeSGabor Kovesdan.Nm grep 5714dc88ebeSGabor Kovesdanutility also supported the flags 5724dc88ebeSGabor Kovesdan.Op Fl ruy . 5734dc88ebeSGabor KovesdanThis implementation supports those options; 5744dc88ebeSGabor Kovesdanhowever, their use is strongly discouraged. 5754dc88ebeSGabor Kovesdan.Sh HISTORY 5764dc88ebeSGabor KovesdanThe 5774dc88ebeSGabor Kovesdan.Nm grep 5784dc88ebeSGabor Kovesdancommand first appeared in 5794dc88ebeSGabor Kovesdan.At v6 . 580