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