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