Blob


1 .TH GREP 1
2 .SH NAME
3 grep, g \- search a file for a pattern
4 .SH SYNOPSIS
5 .B grep
6 [
7 .I option ...
8 ]
9 .I pattern
10 [
11 .I file ...
12 ]
13 .B g
14 [
15 .I option ...
16 ]
17 .I pattern
18 [
19 .I file ...
20 ]
21 .SH DESCRIPTION
22 .I Grep\^
23 searches the input
24 .I files\^
25 (standard input default)
26 for lines that match the
27 .IR pattern ,
28 a regular expression as defined in
29 .IR regexp (7)
30 with the addition of a newline character as an alternative
31 (substitute for
32 .BR | )
33 with lowest precedence.
34 Normally, each line matching the pattern is `selected',
35 and each selected line is copied to the standard output.
36 The options are
37 .TP
38 .B -c
39 Print only a count of matching lines.
40 .PD 0
41 .TP
42 .B -h
43 Do not print file name tags (headers) with output lines.
44 .TP
45 .B -e
46 The following argument is taken as a
47 .IR pattern .
48 This option makes it easy to specify patterns that
49 might confuse argument parsing, such as
50 .BR -n .
51 .TP
52 .B -i
53 Ignore alphabetic case distinctions. The implementation
54 folds into lower case all letters in the pattern and input before
55 interpretation. Matched lines are printed in their original form.
56 .TP
57 .B -l
58 (ell) Print the names of files with selected lines; don't print the lines.
59 .TP
60 .B -L
61 Print the names of files with no selected lines;
62 the converse of
63 .BR -l .
64 .TP
65 .B -n
66 Mark each printed line with its line number counted in its file.
67 .TP
68 .B -s
69 Produce no output, but return status.
70 .TP
71 .B -v
72 Reverse: print lines that do not match the pattern.
73 .TP
74 .B -f
75 The pattern argument is the name of a file containing regular
76 expressions one per line.
77 .TP
78 .B -b
79 Don't buffer the output: write each output line as soon as it is discovered.
80 .PD
81 .PP
82 Output lines are tagged by file name when there is more than one
83 input file.
84 (To force this tagging, include
85 .B /dev/null
86 as a file name argument.)
87 .PP
88 Care should be taken when
89 using the shell metacharacters
90 .B $*[^|()=\e
91 and newline
92 in
93 .IR pattern ;
94 it is safest to enclose the
95 entire expression
96 in single quotes
97 .BR \&\|' \|.\|.\|.\| ' .
98 An expression starting with '*'
99 will treat the rest of the expression
100 as literal characters.
101 .PP
102 .I G
103 invokes grep with
104 .B -n
105 and forces tagging of output lines by file name.
106 If no files are listed, it searches all files matching
107 .IP
108 .EX
109 *.C *.b *.c *.h *.m *.cc *.java *.py *.tex *.ms
110 .EE
111 .SH SOURCE
112 .B /usr/local/plan9/src/cmd/grep
113 .br
114 .B /usr/local/plan9/bin/g
115 .SH SEE ALSO
116 .IR ed (1),
117 .IR awk (1),
118 .IR sed (1),
119 .IR sam (1),
120 .IR regexp (7)
121 .SH DIAGNOSTICS
122 Exit status is null if any lines are selected,
123 or non-null when no lines are selected or an error occurs.