162020Sbostic.\" Copyright (c) 1980, 1990, 1993 262020Sbostic.\" The Regents of the University of California. All rights reserved. 319148Smckusick.\" 450667Scael.\" %sccs.include.redist.roff% 519148Smckusick.\" 6*66877Sbostic.\" @(#)grep.1 8.3 (Berkeley) 04/18/94 743694Scael.\" 843694Scael.Dd 943694Scael.Dt GREP 1 1047344Scael.Os 1143694Scael.Sh NAME 1243694Scael.Nm grep 1343694Scael.Nd file pattern searcher 1443694Scael.Sh SYNOPSIS 1543694Scael.Nm grep 1643694Scael.Op Fl bchilnosvw 1743694Scael.Op Fl e Ar pattern 1850667Scael.Op Ar 1943694Scael.Nm egrep 2043694Scael.Op Fl bchilnosv 2143694Scael.Op Fl e Ar pattern 2243694Scael.Op Fl f Ar pattern_file 2350667Scael.Op Ar 2443694Scael.Nm fgrep 2543694Scael.Op Fl bchilnosvx 2643694Scael.Op Fl e Ar pattern 2743694Scael.Op Fl f Ar pattern_file 2850667Scael.Op Ar 2943694Scael.Sh DESCRIPTION 3043694ScaelThe 3143694Scael.Nm grep 3243694Scaelutilities search the given input files selecting lines 3343694Scaelwhich match one or more patterns; the type of patterns is controlled 3443694Scaelby the options specified. 3543694ScaelBy default, a pattern 3643694Scaelmatches an input line if any regular expression (RE) in the 3743694Scaelpattern matches the input line without its trailing <new-line>. 3843694ScaelA null RE matches every line. 3943694ScaelEach input line that matches at 4043694Scaelleast one of the patterns is written to the standard output. 4143694Scael.Pp 4243694ScaelFor simple patterns or 4343694Scael.Xr ex 1 4443694Scaelor 4543694Scael.Xr ed 1 4643694Scaelstyle regular expressions, the 4743694Scael.Nm grep 4843694Scaelutility is used. 4943694ScaelThe 5043694Scael.Nm egrep 5143694Scaelutility 5243694Scaelcan handle extended regular expressions and 5365227Smckusickembedded <newline>s in patterns. 5465227SmckusickThe 5550667Scael.Nm fgrep 5665227Smckusickutility is quick but can handle only fixed strings. 5743694ScaelA fixed string 5843694Scaelis a string of characters, 5943694Scaeleach character 6043694Scaelis matched only by itself. 6143694ScaelThe pattern 6243694Scaelvalue can consist of multiple lines with 6343694Scaelembedded <newline>s. 6443694ScaelIn this case, the <newline>s 6543694Scaelact as alternation characters, allowing any of the 6643694Scaelpattern lines to match a portion of the input. 6743694Scael.Pp 6843694ScaelThe following options are available: 6943694Scael.Pp 7050667Scael.Bl -tag -width indent 7150667Scael.It Fl b 7243694ScaelThe block number on the disk in which a matched pattern is located 7343694Scaelis displayed in front of the respective matched line. 7450667Scael.It Fl c 7543694ScaelOnly a count of selected lines is written to standard 7643694Scaeloutput. 7750667Scael.It Fl e Ar expression 7843694ScaelSpecify a pattern used during the search of the 7943694Scaelinput. 8043694ScaelMultiple 8143694Scael.Fl e 8243694Scaeloptions can be used to specify 8365227Smckusickmultiple patterns; an input line is selected if it 8443694Scaelmatches any of the specified patterns. 8550667Scael.It Fl f Ar pattern_file 8643694ScaelThe pattern is read from the file named by the 8743694Scaelpathname pattern_file. 8843694ScaelTrailing newlines 8943694Scaelin the pattern_file are ignored. 9050667Scael.Pf ( Nm Egrep 9143694Scaeland 9243694Scael.Nm fgrep 9319148Smckusickonly). 9450667Scael.It Fl h 9532367SbosticNever print filename headers with output lines. 9650667Scael.It Fl i 9743694ScaelThe case of letters is ignored in making comparisons \- that is, upper and 9843694Scaellower case are considered identical. 9950667Scael.It Fl l 10043694ScaelOnly the names of files containing selected lines 10143694Scaelare written to standard output. 10243694ScaelPathnames are 10343694Scaellisted once per file searched. 10443694ScaelIf the standard 10543694Scaelinput is searched, the pathname 10644955Scael.Sq Fl 10743694Scaelis written. 10850667Scael.It Fl n 10943694ScaelEach output line is preceded by its relative line 11043694Scaelnumber in the file; each file starting at line 1. 11143694ScaelThe line number counter is reset for each file processed. 11243694ScaelThis option is ignored if 11343694Scael.Fl c , 11443694Scael.Fl l , 11543694Scaelor 11643694Scael.Fl s 11743694Scaelis 11843694Scaelspecified. 11950667Scael.It Fl o 12032367SbosticAlways print filename headers with output lines. 12150667Scael.It Fl s 12219149SmckusickSilent mode. Nothing is printed (except error messages). 12319148SmckusickThis is useful for checking the error status. 12450667Scael.It Fl v 12543694ScaelSelected lines are those 12643694Scael.Em not 12743694Scaelmatching the specified 12843694Scaelpatterns. 12950667Scael.It Fl x 13043694ScaelOnly input lines selected against an entire fixed 13143694Scaelstring or regular expression are considered to be 13243694Scaelmatching lines. 13350667Scael.Pf ( Nm Fgrep 13443694Scaelonly). 13550667Scael.It Fl w 13619148SmckusickThe expression is searched for as a word 13719148Smckusick(as if surrounded by `\e<' and `\e>', see 13843694Scael.Xr ex 1 . ) 13950667Scael.Pf ( Nm Grep 14043694Scaelonly) 14143694Scael.Pp 14250667Scael.El 14343694ScaelIf no file arguments are specified, the 14443694Scaelstandard input is used. 14543694Scael.Pp 14643694ScaelThe 14743694Scael.Nm grep 14843694Scaelutility exits with one of the following values: 14950667Scael.Pp 15050667Scael.Bl -tag -width flag -compact 15150667Scael.It Li 0 15243694ScaelOne or more lines were selected. 15350667Scael.It Li 1 15443694ScaelNo lines were selected. 15550667Scael.It Li >1 15643694ScaelAn error occurred. 15750667Scael.El 15843694Scael.Sh EXTENDED REGULAR EXPRESSIONS 15943694ScaelThe following characters are interpreted by 16043694Scael.Nm egrep : 16150667Scael.Pp 16250667Scael.Bl -tag -width flag -compact 16350667Scael.It Cm \&$ 16443694ScaelAlign the match from the end of the line. 16550667Scael.It Cm \&^ 16643694ScaelAlign the match from the beginning of the line. 16750667Scael.It Cm \&| 16843694ScaelAdd another pattern (see example below). 16950667Scael.It Cm \&? 17043694ScaelMatch 1 or less sequential repetitions of the pattern. 17150667Scael.It Cm \&+ 17243694ScaelMatch 1 or more sequential repetitions of the pattern. 17350667Scael.It Cm \&* 17443694ScaelMatch 0 or more sequential repetitions of the pattern. 17550667Scael.It Cm \&[] 17643694ScaelMatch any single character or range of characters 17743694Scaelenclosed in the brackets. 17850667Scael.It Cm \&\e 17943694ScaelEscape special characters which have meaning to 18043694Scael.Nm egrep , 18143694Scaelthe set of {$,.,^,[,],|,?,+,*,(,)}. 18250667Scael.El 18343694Scael.Sh EXAMPLES 184*66877SbosticTo find all occurrences of the word patricia in a file: 18544955Scael.Pp 18643694Scael.Dl grep patricia myfile 18743694Scael.Pp 188*66877SbosticTo find all occurrences of the pattern 18950667Scael.Ql \&.Pp 19043694Scaelat the beginning of a line: 19144955Scael.Pp 19243694Scael.Dl grep '^\e.Pp' 19343694Scael.Pp 19465227SmckusickThe apostrophes assure the entire expression is evaluated by 19543694Scael.Nm grep 19643694Scaelinstead of by the 19743694Scaelusers shell. 19843694ScaelThe carat or hat 19950667Scael.Ql Li \&^ 20043694Scaelmeans 20143694Scael.Em from the beginning of a line , 20243694Scaeland the 20350667Scael.Ql Li \&\e 20443694Scaelescapes the 20550667Scael.Ql Li \&. 20643694Scaelwhich would otherwise match any character. 20743694Scael.Pp 20843694ScaelA simple example of an extended regular expression: 20944955Scael.Pp 21043694Scael.Dl egrep '19|20|25' calendar 21143694Scael.Pp 21243694ScaelPeruses the file calendar looking for either 19, 20 21343694Scaelor 25. 21443694Scael.Sh SEE ALSO 21543694Scael.Xr ed 1 , 21643694Scael.Xr ex 1 , 21743694Scael.Xr sed 1 21843694Scael.Sh HISTORY 21950667ScaelThe 22050667Scael.Nm grep 22150667Scaelcommand appeared in 22250667Scael.At v6 . 22343694Scael.Sh BUGS 22419149SmckusickLines are limited to 256 characters; longer lines are truncated. 225