Changeset View
Changeset View
Standalone View
Standalone View
usr.bin/grep/grep.1
Show First 20 Lines • Show All 450 Lines • ▼ Show 20 Lines | |||||
.It Li 1 | .It Li 1 | ||||
No lines were selected. | No lines were selected. | ||||
.It Li \*(Gt1 | .It Li \*(Gt1 | ||||
An error occurred. | An error occurred. | ||||
.El | .El | ||||
.Sh EXAMPLES | .Sh EXAMPLES | ||||
.Bl -dash | .Bl -dash | ||||
.It | .It | ||||
To find all occurrences of the word | Find all occurrences of the text | ||||
bcr: I'd just use "word" or "pattern" here instead of text to be consistent. | |||||
.Sq patricia | .Sq patricia | ||||
in a file: | in a file: | ||||
.Pp | .Pp | ||||
.Dl $ grep 'patricia' myfile | .Dl $ grep 'patricia' myfile | ||||
.It | .It | ||||
To find all occurrences of the pattern | Same as above but looking only for complete words: | ||||
.Pp | |||||
.Dl $ grep -w 'patricia' myfile | |||||
.It | |||||
Count occurrences of the text | |||||
.Sq foo | |||||
: | |||||
.Bd -literal -offset indent | |||||
$ grep -c foo myfile | |||||
.Ed | |||||
.It | |||||
Find all occurrences of the pattern | |||||
.Ql .Pp | .Ql .Pp | ||||
at the beginning of a line: | at the beginning of a line: | ||||
.Pp | .Pp | ||||
.Dl $ grep '^\e.Pp' myfile | .Dl $ grep '^\e.Pp' myfile | ||||
.Pp | .Pp | ||||
The apostrophes ensure the entire expression is evaluated by | The apostrophes ensure the entire expression is evaluated by | ||||
.Nm grep | .Nm grep | ||||
instead of by the user's shell. | instead of by the user's shell. | ||||
The caret | The caret | ||||
.Ql ^ | .Ql ^ | ||||
matches the null string at the beginning of a line, | matches the null string at the beginning of a line, | ||||
and the | and the | ||||
.Ql \e | .Ql \e | ||||
escapes the | escapes the | ||||
.Ql \&. , | .Ql \&. , | ||||
which would otherwise match any character. | which would otherwise match any character. | ||||
.It | .It | ||||
To find all lines in a file which do not contain the words | Find all lines in a file which do not contain the words | ||||
.Sq foo | .Sq foo | ||||
or | or | ||||
.Sq bar : | .Sq bar : | ||||
.Pp | .Pp | ||||
.Dl $ grep -v -e 'foo' -e 'bar' myfile | .Dl $ grep -v -e 'foo' -e 'bar' myfile | ||||
.It | .It | ||||
A simple example of an extended regular expression: | Peruse the file | ||||
.Sq calendar | |||||
looking for either 19, 20, or 25 using extended regular expressions: | |||||
.Pp | .Pp | ||||
.Dl $ egrep '19|20|25' calendar | .Dl $ egrep '19|20|25' calendar | ||||
.It | |||||
Show matching lines and the name of the | |||||
.Sq *.h | |||||
files which contain the text | |||||
.Sq FIXME | |||||
ignoring case. | |||||
Do the search recursively from the | |||||
.Pa /usr/src/sys/arm | |||||
directory | |||||
.Pp | .Pp | ||||
Peruses the file | .Dl $ grep -H -i -R FIXME --include=*.h /usr/src/sys/arm/ | ||||
.Sq calendar | .It | ||||
looking for either 19, 20, or 25. | Same as above but showing only the name of the matching file: | ||||
.Pp | |||||
.Dl $ grep -l -i -R FIXME --include=*.h /usr/src/sys/arm/ | |||||
.It | |||||
Show lines containing the text | |||||
.Sq foo . | |||||
The matching part of the output is colored and every line is prefixed with | |||||
the line number and the offset in the file for those lines that matched. | |||||
.Pp | |||||
.Dl $ grep -b --colour -n foo myfile | |||||
.It | |||||
Show lines that match the extended regular expression patterns read from the | |||||
standard input: | |||||
.Pp | |||||
.Dl $ echo -e 'Free\enBSD\enAll.*reserved' | grep -E -f - myfile | |||||
.It | |||||
Show lines from the output of the | |||||
.Xr pciconf 8 | |||||
command matching the specified extended regular expression along with | |||||
three lines of leading context and one line of trailing context: | |||||
.Pp | |||||
.Dl $ pciconf -lv | grep -B3 -A1 -E 'class.*=.*storage' | |||||
.It | |||||
Suppress any output and use the exit status to show an appropriate message: | |||||
.Pp | |||||
.Dl $ grep -q foo myfile && echo File matches | |||||
.El | .El | ||||
.Sh SEE ALSO | .Sh SEE ALSO | ||||
.Xr ed 1 , | .Xr ed 1 , | ||||
.Xr ex 1 , | .Xr ex 1 , | ||||
.Xr sed 1 , | .Xr sed 1 , | ||||
.Xr zgrep 1 , | .Xr zgrep 1 , | ||||
.Xr re_format 7 | .Xr re_format 7 | ||||
.Sh STANDARDS | .Sh STANDARDS | ||||
Show All 26 Lines |
I'd just use "word" or "pattern" here instead of text to be consistent.