1.\" Copyright (c) 1980, 1990 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" %sccs.include.redist.man% 5.\" 6.\" @(#)grep.1 6.6 (Berkeley) 03/14/91 7.\" 8.Vx 9.Vx 10.Dd 11.Dt GREP 1 12.Os 13.Sh NAME 14.Nm grep 15.Nd file pattern searcher 16.Sh SYNOPSIS 17.Nm grep 18.Op Fl bchilnosvw 19.Op Fl e Ar pattern 20.Ar 21.Nm egrep 22.Op Fl bchilnosv 23.Op Fl e Ar pattern 24.Op Fl f Ar pattern_file 25.Ar 26.Nm fgrep 27.Op Fl bchilnosvx 28.Op Fl e Ar pattern 29.Op Fl f Ar pattern_file 30.Ar 31.Sh DESCRIPTION 32The 33.Nm grep 34utilities search the given input files selecting lines 35which match one or more patterns; the type of patterns is controlled 36by the options specified. 37By default, a pattern 38matches an input line if any regular expression (RE) in the 39pattern matches the input line without its trailing <new-line>. 40A null RE matches every line. 41Each input line that matches at 42least one of the patterns is written to the standard output. 43.Pp 44For simple patterns or 45.Xr ex 1 46or 47.Xr ed 1 48style regular expressions, the 49.Nm grep 50utility is used. 51The 52.Nm egrep 53utility 54can handle extended regular expressions and 55embedded <newline>s in pattern 56.Nm Fgrep 57is quick but is designed to handle fixed strings. 58A fixed string 59is a string of characters, 60each character 61is matched only by itself. 62The pattern 63value can consist of multiple lines with 64embedded <newline>s. 65In this case, the <newline>s 66act as alternation characters, allowing any of the 67pattern lines to match a portion of the input. 68.Pp 69The following options are available: 70.Pp 71.Tw Fl 72.Tp Fl b 73The block number on the disk in which a matched pattern is located 74is displayed in front of the respective matched line. 75.Tp Fl c 76Only a count of selected lines is written to standard 77output. 78.Tc Fl e 79.Ws 80.Ar expression 81.Cx 82Specify a pattern used during the search of the 83input. 84Multiple 85.Fl e 86options can be used to specify 87multiple patterns; an input line is selected of it 88matches any of the specified patterns. 89.Tc Fl f 90.Ws 91.Ar pattern_file 92.Cx 93The pattern is read from the file named by the 94pathname pattern_file. 95Trailing newlines 96in the pattern_file are ignored. 97.Pf \&( Nm egrep 98and 99.Nm fgrep 100only). 101.Tp Fl h 102Never print filename headers with output lines. 103.Tp Fl i 104The case of letters is ignored in making comparisons \- that is, upper and 105lower case are considered identical. 106.Tp Fl l 107Only the names of files containing selected lines 108are written to standard output. 109Pathnames are 110listed once per file searched. 111If the standard 112input is searched, the pathname 113.Sq Fl 114is written. 115.Tp Fl n 116Each output line is preceded by its relative line 117number in the file; each file starting at line 1. 118The line number counter is reset for each file processed. 119This option is ignored if 120.Fl c , 121.Fl l , 122or 123.Fl s 124is 125specified. 126.Tp Fl o 127Always print filename headers with output lines. 128.Tp Fl s 129Silent mode. Nothing is printed (except error messages). 130This is useful for checking the error status. 131.Tp Fl v 132Selected lines are those 133.Em not 134matching the specified 135patterns. 136.Tp Fl x 137Only input lines selected against an entire fixed 138string or regular expression are considered to be 139matching lines. 140.Pf \&( Nm fgrep 141only). 142.Tp Fl w 143The expression is searched for as a word 144(as if surrounded by `\e<' and `\e>', see 145.Xr ex 1 . ) 146.Pf \&( Nm grep 147only) 148.Pp 149.Tp 150If no file arguments are specified, the 151standard input is used. 152.Pp 153The 154.Nm grep 155utility exits with one of the following values: 156.Dw Ds 157.Dp Li \&0 158One or more lines were selected. 159.Dp Li \&1 160No lines were selected. 161.Dp Li \&>1 162An error occurred. 163.Dp 164.Sh EXTENDED REGULAR EXPRESSIONS 165The following characters are interpreted by 166.Nm egrep : 167.Tw Ds 168.Tp Cm \&$ 169Align the match from the end of the line. 170.Tp Cm \&^ 171Align the match from the beginning of the line. 172.Tp Cm \&| 173Add another pattern (see example below). 174.Tp Cm \&? 175Match 1 or less sequential repetitions of the pattern. 176.Tp Cm \&+ 177Match 1 or more sequential repetitions of the pattern. 178.Tp Cm \&* 179Match 0 or more sequential repetitions of the pattern. 180.Tp Cm \&[] 181Match any single character or range of characters 182enclosed in the brackets. 183.Tp Cm \&\e 184Escape special characters which have meaning to 185.Nm egrep , 186the set of {$,.,^,[,],|,?,+,*,(,)}. 187.Tp 188.Sh EXAMPLES 189To find all occurances of the word patricia in a file: 190.Pp 191.Dl grep patricia myfile 192.Pp 193To find all occurences to the pattern 194.Sq Li \&.Pp 195at the beginning of a line: 196.Pp 197.Dl grep '^\e.Pp' 198.Pp 199The apostrophys assure the entire expression is evaluated by 200.Nm grep 201instead of by the 202users shell. 203The carat or hat 204.Sq Li \&^ 205means 206.Em from the beginning of a line , 207and the 208.Sq Li \&\e 209escapes the 210.Sq Li \&. 211which would otherwise match any character. 212.Pp 213A simple example of an extended regular expression: 214.Pp 215.Dl egrep '19|20|25' calendar 216.Pp 217Peruses the file calendar looking for either 19, 20 218or 25. 219.Sh SEE ALSO 220.Xr ed 1 , 221.Xr ex 1 , 222.Xr sed 1 223.Sh HISTORY 224.Nm Grep 225appeared in Version 6 AT&T Unix. 226.Sh BUGS 227Lines are limited to 256 characters; longer lines are truncated. 228