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