CTAGS not defined
[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.\"
75288a28 5.\" @(#)grep.1 6.3 (Berkeley) %G%
732dc260 6.\"
5c7ef023 7.TH GREP 1 ""
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 63.TP
75288a28
KB
64.B \-h
65Never print filename headers with output lines.
66.TP
67.B \-o
68Always print filename headers with output lines.
69.TP
732dc260 70.B \-i
eb0cef48 71The case of letters is ignored in making comparisons \(em that is, upper and
0887f810 72lower case are considered identical.
732dc260
KM
73.TP
74.B \-s
eb0cef48 75Silent mode. Nothing is printed (except error messages).
732dc260
KM
76This is useful for checking the error status.
77.TP
78.B \-w
79The expression is searched for as a word
80(as if surrounded by `\e<' and `\e>', see
81.IR ex (1).)
82(\fIgrep\fR\| only)
83.TP
84.BI \-e " expression"
85Same as a simple
86.I expression
eb0cef48 87argument, but useful when the
732dc260
KM
88.I expression
89begins with a \-.
90.TP
91.BI \-f " file"
75288a28 92The regular expression (\fIegrep\fP) or string list
732dc260
KM
93.RI ( fgrep )
94is taken from the
95.I file.
eb0cef48 96.LP
732dc260 97In all cases the file name is shown if there is more than one input file.
eb0cef48 98Care should be taken when using the characters $ * [ ^ | ( ) and \\ in the
732dc260 99.I expression
eb0cef48 100as they are also meaningful to the Shell. It is safest to enclose the entire
732dc260
KM
101.I expression
102argument in single quotes \' \'.
eb0cef48 103.LP
732dc260
KM
104.I Fgrep
105searches for lines that contain one of the (newline-separated)
106.I strings.
eb0cef48 107.LP
732dc260
KM
108.I Egrep
109accepts extended regular expressions.
eb0cef48 110In the following description `character' excludes newline:
732dc260 111.IP
eb0cef48 112A \e followed by a single character other than newline matches that character.
732dc260 113.IP
eb0cef48
KM
114The character ^ matches the beginning of a line.
115.IP
116The character $ matches the end of a line.
732dc260
KM
117.IP
118A
119.B .
eb0cef48 120(period) matches any character.
732dc260
KM
121.IP
122A single character not otherwise endowed with special
123meaning matches that character.
124.IP
eb0cef48
KM
125A string enclosed in brackets [\|] matches any single character from the string.
126Ranges of ASCII character codes may be abbreviated as in `a\-z0\-9'.
732dc260
KM
127A ]
128may occur only as the first character of the string.
eb0cef48 129A literal \- must be placed where it can't be mistaken as a range indicator.
732dc260 130.IP
eb0cef48
KM
131A regular expression followed by an * (asterisk) matches a sequence of 0
132or more matches of the regular expression.
133A regular expression followed by a + (plus) matches a sequence of 1 or more
732dc260 134matches of the regular expression.
eb0cef48
KM
135A regular expression followed by a ? (question mark) matches a sequence of
1360 or 1 matches of the regular expression.
732dc260 137.IP
eb0cef48
KM
138Two regular expressions concatenated match a match of the first followed
139by a match of the second.
732dc260
KM
140.IP
141Two regular expressions separated by | or newline
eb0cef48 142match either a match for the first or a match for the second.
732dc260
KM
143.IP
144A regular expression enclosed in parentheses
145matches a match for the regular expression.
146.LP
eb0cef48
KM
147The order of precedence of operators at the same parenthesis level
148is [\|] then *+? then concatenation then | and newline.
149.LP
150Ideally there should be only one
151.I grep,
152but we don't know a single algorithm that spans a wide enough
153range of space-time tradeoffs.
732dc260
KM
154.SH "SEE ALSO"
155ex(1),
156sed(1),
157sh(1)
158.SH DIAGNOSTICS
159Exit status is 0 if any matches are found,
1601 if none, 2 for syntax errors or inaccessible files.
161.SH BUGS
eb0cef48 162Lines are limited to 256 characters; longer lines are truncated.