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