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