2011-03-30 13:49:47 +00:00
|
|
|
.TH GREP 1
|
|
|
|
.SH NAME
|
2012-07-05 18:12:04 +00:00
|
|
|
grep, g \- search a file for a pattern
|
2011-03-30 13:49:47 +00:00
|
|
|
.SH SYNOPSIS
|
|
|
|
.B grep
|
|
|
|
[
|
|
|
|
.B -bchiLlnsv
|
|
|
|
]
|
|
|
|
[
|
|
|
|
.B -e
|
|
|
|
]
|
|
|
|
.I pattern
|
|
|
|
|
|
|
|
|
.B -f
|
|
|
|
.I patternfile
|
|
|
|
[
|
|
|
|
.I file ...
|
|
|
|
]
|
2012-07-05 18:12:04 +00:00
|
|
|
.br
|
|
|
|
.B g
|
|
|
|
[
|
|
|
|
.B flags
|
|
|
|
]
|
|
|
|
.I pattern
|
|
|
|
[
|
|
|
|
.I file ...
|
|
|
|
]
|
2011-03-30 13:49:47 +00:00
|
|
|
.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 (6)
|
|
|
|
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.
|
2021-11-01 17:07:28 +00:00
|
|
|
.PP
|
|
|
|
The options are:
|
2011-03-30 13:49:47 +00:00
|
|
|
.TP
|
|
|
|
.B -c
|
|
|
|
Print only a count of matching lines.
|
|
|
|
.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.
|
2012-07-05 18:12:04 +00:00
|
|
|
.PP
|
|
|
|
.I G\^
|
|
|
|
invokes
|
|
|
|
.I grep
|
|
|
|
with
|
|
|
|
.B -n
|
2021-11-01 20:49:43 +00:00
|
|
|
(plus additional flags, if provided)
|
2012-07-05 18:12:04 +00:00
|
|
|
and forces tagging of output lines by file name. If no files
|
2019-06-05 05:36:32 +00:00
|
|
|
are listed, it recursively searches the current directory for
|
|
|
|
all files matching
|
2021-11-01 15:22:41 +00:00
|
|
|
.B *.b *.c *.C *.h *.l *.m
|
|
|
|
.B *.s *.y
|
|
|
|
.B *.asm *.awk *.cc *.cgi *.cpp *.cs
|
|
|
|
.B *.go *.goc *.hs *.java *.lua *.lx
|
|
|
|
.B *.mk *.ml *.mli *.ms *.myr *.pl
|
|
|
|
.B *.py *.rc *.sh *.tex *.xy
|
2019-06-05 05:36:32 +00:00
|
|
|
.PP
|
|
|
|
The recursive search can be suppressed by passing g the
|
|
|
|
.B -n
|
|
|
|
flag.
|
2011-03-30 13:49:47 +00:00
|
|
|
.SH SOURCE
|
|
|
|
.B /sys/src/cmd/grep
|
2012-07-05 18:12:04 +00:00
|
|
|
.br
|
|
|
|
.B /rc/bin/g
|
2011-03-30 13:49:47 +00:00
|
|
|
.SH SEE ALSO
|
|
|
|
.IR ed (1),
|
|
|
|
.IR awk (1),
|
|
|
|
.IR sed (1),
|
|
|
|
.IR sam (1),
|
|
|
|
.IR regexp (6)
|
|
|
|
.SH DIAGNOSTICS
|
|
|
|
Exit status is null if any lines are selected,
|
|
|
|
or non-null when no lines are selected or an error occurs.
|