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