143694Scael.\" Copyright (c) 1980, 1990 The Regents of the University of California. 243694Scael.\" All rights reserved. 319148Smckusick.\" 4*50667Scael.\" %sccs.include.redist.roff% 519148Smckusick.\" 6*50667Scael.\" @(#)grep.1 6.7 (Berkeley) 07/29/91 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 18*50667Scael.Op Ar 1943694Scael.Nm egrep 2043694Scael.Op Fl bchilnosv 2143694Scael.Op Fl e Ar pattern 2243694Scael.Op Fl f Ar pattern_file 23*50667Scael.Op Ar 2443694Scael.Nm fgrep 2543694Scael.Op Fl bchilnosvx 2643694Scael.Op Fl e Ar pattern 2743694Scael.Op Fl f Ar pattern_file 28*50667Scael.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 5343694Scaelembedded <newline>s in pattern 54*50667Scael.Nm fgrep 5543694Scaelis quick but is designed to handle fixed strings. 5643694ScaelA fixed string 5743694Scaelis a string of characters, 5843694Scaeleach character 5943694Scaelis matched only by itself. 6043694ScaelThe pattern 6143694Scaelvalue can consist of multiple lines with 6243694Scaelembedded <newline>s. 6343694ScaelIn this case, the <newline>s 6443694Scaelact as alternation characters, allowing any of the 6543694Scaelpattern lines to match a portion of the input. 6643694Scael.Pp 6743694ScaelThe following options are available: 6843694Scael.Pp 69*50667Scael.Bl -tag -width indent 70*50667Scael.It Fl b 7143694ScaelThe block number on the disk in which a matched pattern is located 7243694Scaelis displayed in front of the respective matched line. 73*50667Scael.It Fl c 7443694ScaelOnly a count of selected lines is written to standard 7543694Scaeloutput. 76*50667Scael.It Fl e Ar expression 7743694ScaelSpecify a pattern used during the search of the 7843694Scaelinput. 7943694ScaelMultiple 8043694Scael.Fl e 8143694Scaeloptions can be used to specify 8243694Scaelmultiple patterns; an input line is selected of it 8343694Scaelmatches any of the specified patterns. 84*50667Scael.It Fl f Ar pattern_file 8543694ScaelThe pattern is read from the file named by the 8643694Scaelpathname pattern_file. 8743694ScaelTrailing newlines 8843694Scaelin the pattern_file are ignored. 89*50667Scael.Pf ( Nm Egrep 9043694Scaeland 9143694Scael.Nm fgrep 9219148Smckusickonly). 93*50667Scael.It Fl h 9432367SbosticNever print filename headers with output lines. 95*50667Scael.It Fl i 9643694ScaelThe case of letters is ignored in making comparisons \- that is, upper and 9743694Scaellower case are considered identical. 98*50667Scael.It Fl l 9943694ScaelOnly the names of files containing selected lines 10043694Scaelare written to standard output. 10143694ScaelPathnames are 10243694Scaellisted once per file searched. 10343694ScaelIf the standard 10443694Scaelinput is searched, the pathname 10544955Scael.Sq Fl 10643694Scaelis written. 107*50667Scael.It Fl n 10843694ScaelEach output line is preceded by its relative line 10943694Scaelnumber in the file; each file starting at line 1. 11043694ScaelThe line number counter is reset for each file processed. 11143694ScaelThis option is ignored if 11243694Scael.Fl c , 11343694Scael.Fl l , 11443694Scaelor 11543694Scael.Fl s 11643694Scaelis 11743694Scaelspecified. 118*50667Scael.It Fl o 11932367SbosticAlways print filename headers with output lines. 120*50667Scael.It Fl s 12119149SmckusickSilent mode. Nothing is printed (except error messages). 12219148SmckusickThis is useful for checking the error status. 123*50667Scael.It Fl v 12443694ScaelSelected lines are those 12543694Scael.Em not 12643694Scaelmatching the specified 12743694Scaelpatterns. 128*50667Scael.It Fl x 12943694ScaelOnly input lines selected against an entire fixed 13043694Scaelstring or regular expression are considered to be 13143694Scaelmatching lines. 132*50667Scael.Pf ( Nm Fgrep 13343694Scaelonly). 134*50667Scael.It Fl w 13519148SmckusickThe expression is searched for as a word 13619148Smckusick(as if surrounded by `\e<' and `\e>', see 13743694Scael.Xr ex 1 . ) 138*50667Scael.Pf ( Nm Grep 13943694Scaelonly) 14043694Scael.Pp 141*50667Scael.El 14243694ScaelIf no file arguments are specified, the 14343694Scaelstandard input is used. 14443694Scael.Pp 14543694ScaelThe 14643694Scael.Nm grep 14743694Scaelutility exits with one of the following values: 148*50667Scael.Pp 149*50667Scael.Bl -tag -width flag -compact 150*50667Scael.It Li 0 15143694ScaelOne or more lines were selected. 152*50667Scael.It Li 1 15343694ScaelNo lines were selected. 154*50667Scael.It Li >1 15543694ScaelAn error occurred. 156*50667Scael.El 15743694Scael.Sh EXTENDED REGULAR EXPRESSIONS 15843694ScaelThe following characters are interpreted by 15943694Scael.Nm egrep : 160*50667Scael.Pp 161*50667Scael.Bl -tag -width flag -compact 162*50667Scael.It Cm \&$ 16343694ScaelAlign the match from the end of the line. 164*50667Scael.It Cm \&^ 16543694ScaelAlign the match from the beginning of the line. 166*50667Scael.It Cm \&| 16743694ScaelAdd another pattern (see example below). 168*50667Scael.It Cm \&? 16943694ScaelMatch 1 or less sequential repetitions of the pattern. 170*50667Scael.It Cm \&+ 17143694ScaelMatch 1 or more sequential repetitions of the pattern. 172*50667Scael.It Cm \&* 17343694ScaelMatch 0 or more sequential repetitions of the pattern. 174*50667Scael.It Cm \&[] 17543694ScaelMatch any single character or range of characters 17643694Scaelenclosed in the brackets. 177*50667Scael.It Cm \&\e 17843694ScaelEscape special characters which have meaning to 17943694Scael.Nm egrep , 18043694Scaelthe set of {$,.,^,[,],|,?,+,*,(,)}. 181*50667Scael.El 18243694Scael.Sh EXAMPLES 18343694ScaelTo find all occurances of the word patricia in a file: 18444955Scael.Pp 18543694Scael.Dl grep patricia myfile 18643694Scael.Pp 187*50667ScaelTo find all occurences of the pattern 188*50667Scael.Ql \&.Pp 18943694Scaelat the beginning of a line: 19044955Scael.Pp 19143694Scael.Dl grep '^\e.Pp' 19243694Scael.Pp 19343694ScaelThe apostrophys assure the entire expression is evaluated by 19443694Scael.Nm grep 19543694Scaelinstead of by the 19643694Scaelusers shell. 19743694ScaelThe carat or hat 198*50667Scael.Ql Li \&^ 19943694Scaelmeans 20043694Scael.Em from the beginning of a line , 20143694Scaeland the 202*50667Scael.Ql Li \&\e 20343694Scaelescapes the 204*50667Scael.Ql Li \&. 20543694Scaelwhich would otherwise match any character. 20643694Scael.Pp 20743694ScaelA simple example of an extended regular expression: 20844955Scael.Pp 20943694Scael.Dl egrep '19|20|25' calendar 21043694Scael.Pp 21143694ScaelPeruses the file calendar looking for either 19, 20 21243694Scaelor 25. 21343694Scael.Sh SEE ALSO 21443694Scael.Xr ed 1 , 21543694Scael.Xr ex 1 , 21643694Scael.Xr sed 1 21743694Scael.Sh HISTORY 218*50667ScaelThe 219*50667Scael.Nm grep 220*50667Scaelcommand appeared in 221*50667Scael.At v6 . 22243694Scael.Sh BUGS 22319149SmckusickLines are limited to 256 characters; longer lines are truncated. 224