manual page distributed with 4.1BSD
[unix-history] / usr / src / usr.bin / grep / egrep / grep.1
CommitLineData
732dc260
KM
1.\" Copyright (c) 1980 Regents of the University of California.
2.\" All rights reserved. The Berkeley software License Agreement
3.\" specifies the terms and conditions for redistribution.
4.\"
5.\" @(#)grep.1 4.1 (Berkeley) %G%
6.\"
7.TH GREP 1 8/11/80
8.UC 4
9.SH NAME
10grep, egrep, fgrep \- search a file for a pattern
11.SH SYNOPSIS
12.B grep
13[ option ] ...
14expression [ file ] ...
15.LP
16.B egrep
17[ option ] ...
18[ expression ]
19[ file ] ...
20.PP
21.B fgrep
22[ option ] ...
23[ strings ]
24[ file ]
25.SH DESCRIPTION
26Commands of the
27.I grep
28family search the input
29.I files
30(standard input default)
31for lines matching
32a pattern.
33Normally, each line found
34is copied to the standard output.
35.I Grep
36patterns are limited regular expressions in the style of
37.IR ex (1);
38it uses a compact nondeterministic algorithm.
39.I Egrep
40patterns are full regular expressions;
41it uses a fast deterministic algorithm that
42sometimes needs exponential space.
43.I Fgrep
44patterns are fixed strings; it is fast and compact.
45The following options are recognized.
46.TP
47.B \-v
48All lines but those matching
49are printed.
50.TP
51.B \-x
52(Exact) only lines matched in their entirety are printed
53.RI ( fgrep
54only).
55.TP
56.B \-c
57Only a count of matching lines is printed.
58.TP
59.B \-l
60The names of files with matching lines are listed (once)
61separated by newlines.
62.TP
63.B \-n
64Each line is preceded by
65its relative line number in the file.
66.TP
67.B \-b
68Each line is preceded by the block number
69on which it was found.
70This is sometimes useful in locating
71disk block numbers by context.
72.TP
73.B \-i
74The case of letters is ignored in making comparisons.
75(E.g. upper and lower case are considered identical.)
76(\fIgrep\fR\| and \fIfgrep\fR only)
77.TP
78.B \-s
79Silent mode.
80Nothing is printed (except error messages).
81This is useful for checking the error status.
82.TP
83.B \-w
84The expression is searched for as a word
85(as if surrounded by `\e<' and `\e>', see
86.IR ex (1).)
87(\fIgrep\fR\| only)
88.TP
89.BI \-e " expression"
90Same as a simple
91.I expression
92argument,
93but useful when the
94.I expression
95begins with a \-.
96.TP
97.BI \-f " file"
98The regular expression
99.RI ( egrep )
100or string list
101.RI ( fgrep )
102is taken from the
103.I file.
104.PP
105In all cases the file name is shown if there is more than one input file.
106Care should be taken when
107using the characters
108$ * [ ^ | ( ) and \\ in the
109.I expression
110as they are
111also meaningful to the Shell.
112It is safest to enclose the
113entire
114.I expression
115argument in single quotes \' \'.
116.PP
117.I Fgrep
118searches for lines that contain one of the (newline-separated)
119.I strings.
120.PP
121.I Egrep
122accepts extended regular expressions.
123In the following description `character' excludes
124newline:
125.IP
126A \e followed by a single character
127other than newline
128matches that character.
129.IP
130The character ^ ($) matches the beginning (end) of
131a line.
132.IP
133A
134.B .
135matches any character.
136.IP
137A single character not otherwise endowed with special
138meaning matches that character.
139.IP
140A string enclosed in brackets [\|]
141matches any single character from the string.
142Ranges of ASCII character codes may be abbreviated
143as in `a\-z0\-9'.
144A ]
145may occur only as the first character of the string.
146A literal \- must be placed where it can't be
147mistaken as a range indicator.
148.IP
149A regular expression followed by * (+, ?) matches a sequence
150of 0 or more (1 or more, 0 or 1)
151matches of the regular expression.
152.IP
153Two regular expressions concatenated
154match a match of the first followed by a match of
155the second.
156.IP
157Two regular expressions separated by | or newline
158match either a match for the first or a match for the
159second.
160.IP
161A regular expression enclosed in parentheses
162matches a match for the regular expression.
163.LP
164The order of precedence of operators
165at the same parenthesis level
166is [\|] then
167*+? then concatenation then | and newline.
168.SH "SEE ALSO"
169ex(1),
170sed(1),
171sh(1)
172.SH DIAGNOSTICS
173Exit status is 0 if any matches are found,
1741 if none, 2 for syntax errors or inaccessible files.
175.SH BUGS
176Ideally there should be only one
177.I grep,
178but we don't know a single algorithm that spans a wide enough
179range of space-time tradeoffs.
180.PP
181Lines
182are limited to 256 characters;
183longer lines are truncated.