143694Scael.\" Copyright (c) 1980, 1990 The Regents of the University of California. 243694Scael.\" All rights reserved. 319148Smckusick.\" 443694Scael.\" %sccs.include.redist.man% 519148Smckusick.\" 6*44955Scael.\" @(#)grep.1 6.5 (Berkeley) 07/24/90 743694Scael.\" 843694Scael.Dd 943694Scael.Dt GREP 1 1043694Scael.Os BSD 4.4 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 1843694Scael.Ar 1943694Scael.Nm egrep 2043694Scael.Op Fl bchilnosv 2143694Scael.Op Fl e Ar pattern 2243694Scael.Op Fl f Ar pattern_file 2343694Scael.Ar 2443694Scael.Nm fgrep 2543694Scael.Op Fl bchilnosvx 2643694Scael.Op Fl e Ar pattern 2743694Scael.Op Fl f Ar pattern_file 2843694Scael.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 5443694Scael.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 6943694Scael.Tw Fl 7043694Scael.Tp Fl b 7143694ScaelThe block number on the disk in which a matched pattern is located 7243694Scaelis displayed in front of the respective matched line. 7343694Scael.Tp Fl c 7443694ScaelOnly a count of selected lines is written to standard 7543694Scaeloutput. 7643694Scael.Tc Fl e 7743694Scael.Ws 7843694Scael.Ar expression 7943694Scael.Cx 8043694ScaelSpecify a pattern used during the search of the 8143694Scaelinput. 8243694ScaelMultiple 8343694Scael.Fl e 8443694Scaeloptions can be used to specify 8543694Scaelmultiple patterns; an input line is selected of it 8643694Scaelmatches any of the specified patterns. 8743694Scael.Tc Fl f 8843694Scael.Ws 8943694Scael.Ar pattern_file 9043694Scael.Cx 9143694ScaelThe pattern is read from the file named by the 9243694Scaelpathname pattern_file. 9343694ScaelTrailing newlines 9443694Scaelin the pattern_file are ignored. 9543694Scael.Pf \&( Nm egrep 9643694Scaeland 9743694Scael.Nm fgrep 9819148Smckusickonly). 9943694Scael.Tp Fl h 10032367SbosticNever print filename headers with output lines. 10143694Scael.Tp Fl i 10243694ScaelThe case of letters is ignored in making comparisons \- that is, upper and 10343694Scaellower case are considered identical. 10443694Scael.Tp Fl l 10543694ScaelOnly the names of files containing selected lines 10643694Scaelare written to standard output. 10743694ScaelPathnames are 10843694Scaellisted once per file searched. 10943694ScaelIf the standard 11043694Scaelinput is searched, the pathname 111*44955Scael.Sq Fl 11243694Scaelis written. 11343694Scael.Tp Fl n 11443694ScaelEach output line is preceded by its relative line 11543694Scaelnumber in the file; each file starting at line 1. 11643694ScaelThe line number counter is reset for each file processed. 11743694ScaelThis option is ignored if 11843694Scael.Fl c , 11943694Scael.Fl l , 12043694Scaelor 12143694Scael.Fl s 12243694Scaelis 12343694Scaelspecified. 12443694Scael.Tp Fl o 12532367SbosticAlways print filename headers with output lines. 12643694Scael.Tp Fl s 12719149SmckusickSilent mode. Nothing is printed (except error messages). 12819148SmckusickThis is useful for checking the error status. 12943694Scael.Tp Fl v 13043694ScaelSelected lines are those 13143694Scael.Em not 13243694Scaelmatching the specified 13343694Scaelpatterns. 13443694Scael.Tp Fl x 13543694ScaelOnly input lines selected against an entire fixed 13643694Scaelstring or regular expression are considered to be 13743694Scaelmatching lines. 13843694Scael.Pf \&( Nm fgrep 13943694Scaelonly). 14043694Scael.Tp Fl w 14119148SmckusickThe expression is searched for as a word 14219148Smckusick(as if surrounded by `\e<' and `\e>', see 14343694Scael.Xr ex 1 . ) 14443694Scael.Pf \&( Nm grep 14543694Scaelonly) 14643694Scael.Pp 14743694Scael.Tp 14843694ScaelIf no file arguments are specified, the 14943694Scaelstandard input is used. 15043694Scael.Pp 15143694ScaelThe 15243694Scael.Nm grep 15343694Scaelutility exits with one of the following values: 154*44955Scael.Dw Ds 155*44955Scael.Dp Li \&0 15643694ScaelOne or more lines were selected. 157*44955Scael.Dp Li \&1 15843694ScaelNo lines were selected. 159*44955Scael.Dp Li \&>1 16043694ScaelAn error occurred. 161*44955Scael.Dp 16243694Scael.Sh EXTENDED REGULAR EXPRESSIONS 16343694ScaelThe following characters are interpreted by 16443694Scael.Nm egrep : 16543694Scael.Tw Ds 16643694Scael.Tp Cm \&$ 16743694ScaelAlign the match from the end of the line. 16843694Scael.Tp Cm \&^ 16943694ScaelAlign the match from the beginning of the line. 17043694Scael.Tp Cm \&| 17143694ScaelAdd another pattern (see example below). 17243694Scael.Tp Cm \&? 17343694ScaelMatch 1 or less sequential repetitions of the pattern. 17443694Scael.Tp Cm \&+ 17543694ScaelMatch 1 or more sequential repetitions of the pattern. 17643694Scael.Tp Cm \&* 17743694ScaelMatch 0 or more sequential repetitions of the pattern. 17843694Scael.Tp Cm \&[] 17943694ScaelMatch any single character or range of characters 18043694Scaelenclosed in the brackets. 18143694Scael.Tp Cm \&\e 18243694ScaelEscape special characters which have meaning to 18343694Scael.Nm egrep , 18443694Scaelthe set of {$,.,^,[,],|,?,+,*,(,)}. 18543694Scael.Tp 18643694Scael.Sh EXAMPLES 18743694ScaelTo find all occurances of the word patricia in a file: 188*44955Scael.Pp 18943694Scael.Dl grep patricia myfile 19043694Scael.Pp 19143694ScaelTo find all occurences to the pattern 19243694Scael.Sq Li \&.Pp 19343694Scaelat the beginning of a line: 194*44955Scael.Pp 19543694Scael.Dl grep '^\e.Pp' 19643694Scael.Pp 19743694ScaelThe apostrophys assure the entire expression is evaluated by 19843694Scael.Nm grep 19943694Scaelinstead of by the 20043694Scaelusers shell. 20143694ScaelThe carat or hat 20243694Scael.Sq Li \&^ 20343694Scaelmeans 20443694Scael.Em from the beginning of a line , 20543694Scaeland the 20643694Scael.Sq Li \&\e 20743694Scaelescapes the 20843694Scael.Sq Li \&. 20943694Scaelwhich would otherwise match any character. 21043694Scael.Pp 21143694ScaelA simple example of an extended regular expression: 212*44955Scael.Pp 21343694Scael.Dl egrep '19|20|25' calendar 21443694Scael.Pp 21543694ScaelPeruses the file calendar looking for either 19, 20 21643694Scaelor 25. 21743694Scael.Sh SEE ALSO 21843694Scael.Xr ed 1 , 21943694Scael.Xr ex 1 , 22043694Scael.Xr sed 1 22143694Scael.Sh HISTORY 22243694Scael.Nm Grep 22343694Scaelappeared in Version 6 AT&T Unix. 22443694Scael.Sh BUGS 22519149SmckusickLines are limited to 256 characters; longer lines are truncated. 226