Name
grep
Synopsis
grep [options
]pattern
[files
]
Searches one or more files
for lines that match a regular expression pattern
. Regular expressions are described in Chapter 6. Exit status is 0 if any lines match, 1 if none match, and 2 for errors. See also
egrep
and
fgrep
.
Options
- -a, --text
Don’t suppress output lines with binary data; treat as text.
-
-A
num
, --after-context=num
Print
num
lines of text that occur after the matching line.- -b, --byte-offset
Print the byte offset within the input file before each line of output.
-
-B
num
, --before-context=num
Print
num
lines of text that occur before the matching line.-
--binary-files=
type
Treat binary files as specified. By default, grep treats binary files as such (
type
is binary). If a matching string is found within a binary file, grep reports only that the file matches; nothing is printed for nonmatching binary files. Iftype
is without-match, grep assumes binary files don’t match and skips them altogether. Same as -I. Using atype
of text causes grep to treat binary files as text and print all matched lines. Same as -a.- -c, --count
Print only a count of matched lines. With the -v or --invert-match option, count nonmatching lines.
-
-C[
num
], --context[=
num
],-
num
Print
num
lines of leading and trailing context. Default context is 2 lines.-
-color[
=
when
], --colour[=
when
] Marks matched text in red, or the contents of
GREP_COLOR
environment variable. Optionalwhen
can be auto, always, or never.-
-d
action
, --directories=action
Get Mac OS X Tiger in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.