xref: /original-bsd/usr.bin/grep/egrep/grep.1 (revision ee109830)
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.4 (Berkeley) 06/24/90
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
98only).
99.Tp Fl h
100Never print filename headers with output lines.
101.Tp Fl i
102The case of letters is ignored in making comparisons \- that is, upper and
103lower case are considered identical.
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
111.Fl
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
127Silent mode.  Nothing is printed (except error messages).
128This is useful for checking the error status.
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
141The expression is searched for as a word
142(as if surrounded by `\e<' and `\e>', see
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:
154.Tw Ds
155.Tp Li \&0
156One or more lines were selected.
157.Tp Li \&1
158No lines were selected.
159.Tp Li \&>1
160An error occurred.
161.Tp
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:
188.Dl grep patricia myfile
189.Pp
190To find all occurences to the pattern
191.Sq Li \&.Pp
192at the beginning of a line:
193.Dl grep '^\e.Pp'
194.Pp
195The apostrophys assure the entire expression is evaluated by
196.Nm grep
197instead of by the
198users shell.
199The carat or hat
200.Sq Li \&^
201means
202.Em from the beginning of a line ,
203and the
204.Sq Li \&\e
205escapes the
206.Sq Li \&.
207which would otherwise match any character.
208.Pp
209A simple example of an extended regular expression:
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
219.Nm Grep
220appeared in Version 6 AT&T Unix.
221.Sh BUGS
222Lines are limited to 256 characters; longer lines are truncated.
223