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