xref: /csrg-svn/usr.bin/grep/egrep/grep.1 (revision 43694)
1*43694Scael.\" Copyright (c) 1980, 1990 The Regents of the University of California.
2*43694Scael.\" All rights reserved.
319148Smckusick.\"
4*43694Scael.\" %sccs.include.redist.man%
519148Smckusick.\"
6*43694Scael.\"     @(#)grep.1	6.4 (Berkeley) 06/24/90
7*43694Scael.\"
8*43694Scael.Dd
9*43694Scael.Dt GREP 1
10*43694Scael.Os BSD 4.4
11*43694Scael.Sh NAME
12*43694Scael.Nm grep
13*43694Scael.Nd file pattern searcher
14*43694Scael.Sh SYNOPSIS
15*43694Scael.Nm grep
16*43694Scael.Op Fl bchilnosvw
17*43694Scael.Op Fl e Ar pattern
18*43694Scael.Ar
19*43694Scael.Nm egrep
20*43694Scael.Op Fl bchilnosv
21*43694Scael.Op Fl e Ar pattern
22*43694Scael.Op Fl f Ar pattern_file
23*43694Scael.Ar
24*43694Scael.Nm fgrep
25*43694Scael.Op Fl bchilnosvx
26*43694Scael.Op Fl e Ar pattern
27*43694Scael.Op Fl f Ar pattern_file
28*43694Scael.Ar
29*43694Scael.Sh DESCRIPTION
30*43694ScaelThe
31*43694Scael.Nm grep
32*43694Scaelutilities search the given input files selecting lines
33*43694Scaelwhich match one or more patterns; the type of patterns is controlled
34*43694Scaelby the options specified.
35*43694ScaelBy default, a pattern
36*43694Scaelmatches an input line if any regular expression (RE) in the
37*43694Scaelpattern matches the input line without its trailing <new-line>.
38*43694ScaelA null RE matches every line.
39*43694ScaelEach input line that matches at
40*43694Scaelleast one of the patterns is written to the standard output.
41*43694Scael.Pp
42*43694ScaelFor simple patterns or
43*43694Scael.Xr ex 1
44*43694Scaelor
45*43694Scael.Xr ed 1
46*43694Scaelstyle regular expressions, the
47*43694Scael.Nm grep
48*43694Scaelutility is used.
49*43694ScaelThe
50*43694Scael.Nm egrep
51*43694Scaelutility
52*43694Scaelcan handle extended regular expressions and
53*43694Scaelembedded <newline>s in pattern
54*43694Scael.Nm Fgrep
55*43694Scaelis quick but is designed to handle fixed strings.
56*43694ScaelA fixed string
57*43694Scaelis a string of characters,
58*43694Scaeleach character
59*43694Scaelis matched only by itself.
60*43694ScaelThe pattern
61*43694Scaelvalue can consist of multiple lines with
62*43694Scaelembedded <newline>s.
63*43694ScaelIn this case, the <newline>s
64*43694Scaelact as alternation characters, allowing any of the
65*43694Scaelpattern lines to match a portion of the input.
66*43694Scael.Pp
67*43694ScaelThe following options are available:
68*43694Scael.Pp
69*43694Scael.Tw Fl
70*43694Scael.Tp Fl b
71*43694ScaelThe block number on the disk in which a matched pattern is located
72*43694Scaelis displayed in front of the respective matched line.
73*43694Scael.Tp Fl c
74*43694ScaelOnly a count of selected lines is written to standard
75*43694Scaeloutput.
76*43694Scael.Tc Fl e
77*43694Scael.Ws
78*43694Scael.Ar expression
79*43694Scael.Cx
80*43694ScaelSpecify a pattern used during the search of the
81*43694Scaelinput.
82*43694ScaelMultiple
83*43694Scael.Fl e
84*43694Scaeloptions can be used to specify
85*43694Scaelmultiple patterns; an input line is selected of it
86*43694Scaelmatches any of the specified patterns.
87*43694Scael.Tc Fl f
88*43694Scael.Ws
89*43694Scael.Ar pattern_file
90*43694Scael.Cx
91*43694ScaelThe pattern is read from the file named by the
92*43694Scaelpathname pattern_file.
93*43694ScaelTrailing newlines
94*43694Scaelin the pattern_file are ignored.
95*43694Scael.Pf \&( Nm egrep
96*43694Scaeland
97*43694Scael.Nm fgrep
9819148Smckusickonly).
99*43694Scael.Tp Fl h
10032367SbosticNever print filename headers with output lines.
101*43694Scael.Tp Fl i
102*43694ScaelThe case of letters is ignored in making comparisons \- that is, upper and
103*43694Scaellower case are considered identical.
104*43694Scael.Tp Fl l
105*43694ScaelOnly the names of files containing selected lines
106*43694Scaelare written to standard output.
107*43694ScaelPathnames are
108*43694Scaellisted once per file searched.
109*43694ScaelIf the standard
110*43694Scaelinput is searched, the pathname
111*43694Scael.Fl
112*43694Scaelis written.
113*43694Scael.Tp Fl n
114*43694ScaelEach output line is preceded by its relative line
115*43694Scaelnumber in the file; each file starting at line 1.
116*43694ScaelThe line number counter is reset for each file processed.
117*43694ScaelThis option is ignored if
118*43694Scael.Fl c ,
119*43694Scael.Fl l ,
120*43694Scaelor
121*43694Scael.Fl s
122*43694Scaelis
123*43694Scaelspecified.
124*43694Scael.Tp Fl o
12532367SbosticAlways print filename headers with output lines.
126*43694Scael.Tp Fl s
12719149SmckusickSilent mode.  Nothing is printed (except error messages).
12819148SmckusickThis is useful for checking the error status.
129*43694Scael.Tp Fl v
130*43694ScaelSelected lines are those
131*43694Scael.Em not
132*43694Scaelmatching the specified
133*43694Scaelpatterns.
134*43694Scael.Tp Fl x
135*43694ScaelOnly input lines selected against an entire fixed
136*43694Scaelstring or regular expression are considered to be
137*43694Scaelmatching lines.
138*43694Scael.Pf \&( Nm fgrep
139*43694Scaelonly).
140*43694Scael.Tp Fl w
14119148SmckusickThe expression is searched for as a word
14219148Smckusick(as if surrounded by `\e<' and `\e>', see
143*43694Scael.Xr ex  1  . )
144*43694Scael.Pf \&( Nm grep
145*43694Scaelonly)
146*43694Scael.Pp
147*43694Scael.Tp
148*43694ScaelIf no file arguments are specified, the
149*43694Scaelstandard input is used.
150*43694Scael.Pp
151*43694ScaelThe
152*43694Scael.Nm grep
153*43694Scaelutility exits with one of the following values:
154*43694Scael.Tw Ds
155*43694Scael.Tp Li \&0
156*43694ScaelOne or more lines were selected.
157*43694Scael.Tp Li \&1
158*43694ScaelNo lines were selected.
159*43694Scael.Tp Li \&>1
160*43694ScaelAn error occurred.
161*43694Scael.Tp
162*43694Scael.Sh EXTENDED REGULAR EXPRESSIONS
163*43694ScaelThe following characters are interpreted by
164*43694Scael.Nm egrep :
165*43694Scael.Tw Ds
166*43694Scael.Tp Cm \&$
167*43694ScaelAlign the match from the end of the line.
168*43694Scael.Tp Cm \&^
169*43694ScaelAlign the match from the beginning of the line.
170*43694Scael.Tp Cm \&|
171*43694ScaelAdd another pattern (see example below).
172*43694Scael.Tp Cm \&?
173*43694ScaelMatch 1 or less sequential repetitions of the pattern.
174*43694Scael.Tp Cm \&+
175*43694ScaelMatch 1 or more sequential repetitions of the pattern.
176*43694Scael.Tp Cm \&*
177*43694ScaelMatch 0 or more sequential repetitions of the pattern.
178*43694Scael.Tp Cm \&[]
179*43694ScaelMatch any single character or range of characters
180*43694Scaelenclosed in the brackets.
181*43694Scael.Tp Cm \&\e
182*43694ScaelEscape special characters which have meaning to
183*43694Scael.Nm egrep ,
184*43694Scaelthe set of {$,.,^,[,],|,?,+,*,(,)}.
185*43694Scael.Tp
186*43694Scael.Sh EXAMPLES
187*43694ScaelTo find all occurances of the word patricia in a file:
188*43694Scael.Dl grep patricia myfile
189*43694Scael.Pp
190*43694ScaelTo find all occurences to the pattern
191*43694Scael.Sq Li \&.Pp
192*43694Scaelat the beginning of a line:
193*43694Scael.Dl grep '^\e.Pp'
194*43694Scael.Pp
195*43694ScaelThe apostrophys assure the entire expression is evaluated by
196*43694Scael.Nm grep
197*43694Scaelinstead of by the
198*43694Scaelusers shell.
199*43694ScaelThe carat or hat
200*43694Scael.Sq Li \&^
201*43694Scaelmeans
202*43694Scael.Em from the beginning of a line ,
203*43694Scaeland the
204*43694Scael.Sq Li \&\e
205*43694Scaelescapes the
206*43694Scael.Sq Li \&.
207*43694Scaelwhich would otherwise match any character.
208*43694Scael.Pp
209*43694ScaelA simple example of an extended regular expression:
210*43694Scael.Dl egrep '19|20|25' calendar
211*43694Scael.Pp
212*43694ScaelPeruses the file calendar looking for either 19, 20
213*43694Scaelor 25.
214*43694Scael.Sh SEE ALSO
215*43694Scael.Xr ed 1 ,
216*43694Scael.Xr ex 1 ,
217*43694Scael.Xr sed 1
218*43694Scael.Sh HISTORY
219*43694Scael.Nm Grep
220*43694Scaelappeared in Version 6 AT&T Unix.
221*43694Scael.Sh BUGS
22219149SmckusickLines are limited to 256 characters; longer lines are truncated.
223