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