Manual Pages for UNIX Darwin command on man egrep
MyWebUniversity

Manual Pages for UNIX Darwin command on man egrep

GREP(1) GREP(1)

NAME

grep, egrep, fgrep - print lines matching a pattern

SYNOPSIS

ggrreepp [options] PATTERN [FILE...]

ggrreepp [options] [-ee PATTERN | -ff FILE] [FILE...]

DESCRIPTION

GGrreepp searches the named input FILEs (or standard input if no files are

named, or the file name - is given) for lines containing a match to the

given PATTERN. By default, ggrreepp prints the matching lines. In addition, two variant programs eeggrreepp and ffggrreepp are available. EEggrreepp

is the same as ggrreepp -EE. FFggrreepp is the same as ggrreepp -FF.

OOPPTTIIOONNSS

-AA NUM, --aafftteerr-ccoonntteexxtt==NUM

Print NUM lines of trailing context after matching lines.

Places a line containing -- between contiguous groups of

matches.

-aa, --tteexxtt

Process a binary file as if it were text; this is equivalent to

the --bbiinnaarryy-ffiilleess==tteexxtt option.

-BB NUM, --bbeeffoorree-ccoonntteexxtt==NUM

Print NUM lines of leading context before matching lines.

Places a line containing -- between contiguous groups of

matches.

-CC NUM, --ccoonntteexxtt==NUM

Print NUM lines of output context. Places a line containing --

between contiguous groups of matches.

-bb, --bbyyttee-ooffffsseett

Print the byte offset within the input file before each line of output.

--bbiinnaarryy-ffiilleess==TYPE

If the first few bytes of a file indicate that the file contains binary data, assume that the file is of type TYPE. By default,

TYPE is bbiinnaarryy, and ggrreepp normally outputs either a one-line mes-

sage saying that a binary file matches, or no message if there

is no match. If TYPE is wwiitthhoouutt-mmaattcchh, ggrreepp assumes that a

binary file does not match; this is equivalent to the -II option.

If TYPE is tteexxtt, ggrreepp processes a binary file as if it were

text; this is equivalent to the -aa option. Warning: ggrreepp

--bbiinnaarryy-ffiilleess==tteexxtt might output binary garbage, which can have

nasty side effects if the output is a terminal and if the termi-

nal driver interprets some of it as commands.

--ccoolloouurr[[==WHEN], --ccoolloorr[[==WHEN]

Surround the matching string with the marker find in GGRREEPPCCOOLLOORR environment variable. WHEN may be `never', `always', or `auto'

-cc, --ccoouunntt

Suppress normal output; instead print a count of matching lines

for each input file. With the -vv, --iinnvveerrtt-mmaattcchh option (see

below), count non-matching lines.

-DD ACTION, --ddeevviicceess==ACTION

If an input file is a device, FIFO or socket, use ACTION to process it. By default, ACTION is rreeaadd, which means that devices are read just as if they were ordinary files. If ACTION is sskkiipp, devices are silently skipped.

-dd ACTION, --ddiirreeccttoorriieess==ACTION

If an input file is a directory, use ACTION to process it. By default, ACTION is rreeaadd, which means that directories are read

just as if they were ordinary files. If ACTION is sskkiipp, direc-

tories are silently skipped. If ACTION is rreeccuurrssee, ggrreepp reads all files under each directory, recursively; this is equivalent

to the -rr option.

-EE, --eexxtteennddeedd-rreeggeexxpp

Interpret PATTERN as an extended regular expression (see below).

-ee PATTERN, --rreeggeexxpp==PATTERN

Use PATTERN as the pattern; useful to protect patterns beginning

with -.

-FF, --ffiixxeedd-ssttrriinnggss

Interpret PATTERN as a list of fixed strings, separated by new-

lines, any of which is to be matched. -PP, --ppeerrll-rreeggeexxpp Inter-

pret PATTERN as a Perl regular expression.

-ff FILE, --ffiillee==FILE

Obtain patterns from FILE, one per line. The empty file con-

tains zero patterns, and therefore matches nothing.

-GG, --bbaassiicc-rreeggeexxpp

Interpret PATTERN as a basic regular expression (see below). This is the default.

-HH, --wwiitthh-ffiilleennaammee

Print the filename for each match.

-hh, --nnoo-ffiilleennaammee

Suppress the prefixing of filenames on output when multiple files are searched.

--hheellpp Output a brief help message.

-II Process a binary file as if it did not contain matching data;

this is equivalent to the --bbiinnaarryy-ffiilleess==wwiitthhoouutt-mmaattcchh option.

-ii, --iiggnnoorree-ccaassee

Ignore case distinctions in both the PATTERN and the input files.

-LL, --ffiilleess-wwiitthhoouutt-mmaattcchh

Suppress normal output; instead print the name of each input file from which no output would normally have been printed. The scanning will stop on the first match.

-ll, --ffiilleess-wwiitthh-mmaattcchheess

Suppress normal output; instead print the name of each input file from which output would normally have been printed. The scanning will stop on the first match.

-mm NUM, --mmaaxx-ccoouunntt==NUM

Stop reading a file after NUM matching lines. If the input is standard input from a regular file, and NUM matching lines are output, ggrreepp ensures that the standard input is positioned to just after the last matching line before exiting, regardless of the presence of trailing context lines. This enables a calling process to resume a search. When ggrreepp stops after NUM matching

lines, it outputs any trailing context lines. When the -cc or

--ccoouunntt option is also used, ggrreepp does not output a count

greater than NUM. When the -vv or --iinnvveerrtt-mmaattcchh option is also

used, ggrreepp stops after outputting NUM non-matching lines.

--mmmmaapp If possible, use the mmmmaapp(2) system call to read input, instead

of the default rreeaadd(2) system call. In some situations, --mmmmaapp

yields better performance. However, --mmmmaapp can cause undefined

behavior (including core dumps) if an input file shrinks while ggrreepp is operating, or if an I/O error occurs.

-nn, --lliinnee-nnuummbbeerr

Prefix each line of output with the line number within its input file.

-oo, --oonnllyy-mmaattcchhiinngg

Show only the part of a matching line that matches PATTERN.

--llaabbeell==LABEL

Displays input actually coming from standard input as input com-

ing from file LABEL. This is especially useful for tools like

zgrep, e.g. ggzziipp -ccdd ffoooo..ggzz ||ggrreepp --llaabbeell==ffoooo ssoommeetthhiinngg

--lliinnee-bbuuffffeerriinngg

Use line buffering, it can be a performance penality.

-qq, --qquuiieett, --ssiilleenntt

Quiet; do not write anything to standard output. Exit immedi-

ately with zero status if any match is found, even if an error

was detected. Also see the -ss or --nnoo-mmeessssaaggeess option.

-RR, -rr, --rreeccuurrssiivvee

Read all files under each directory, recursively; this is equiv-

alent to the -dd rreeccuurrssee option.

--iinncclluuddee==PATTERN

Recurse in directories only searching file matching PATTERN.

--eexxcclluuddee==PATTERN

Recurse in directories skip file matching PATTERN.

-ss, --nnoo-mmeessssaaggeess

Suppress error messages about nonexistent or unreadable files.

Portability note: unlike GNU ggrreepp, traditional ggrreepp did not con-

form to POSIX.2, because traditional ggrreepp lacked a -qq option and

its -ss option behaved like GNU ggrreepp's -qq option. Shell scripts

intended to be portable to traditional ggrreepp should avoid both -qq

and -ss and should redirect output to /dev/null instead.

-UU, --bbiinnaarryy

Treat the file(s) as binary. By default, under MS-DOS and MS-

Windows, ggrreepp guesses the file type by looking at the contents of the first 32KB read from the file. If ggrreepp decides the file is a text file, it strips the CR characters from the original

file contents (to make regular expressions with ^^ and $$ work

correctly). Specifying -UU overrules this guesswork, causing all

files to be read and passed to the matching mechanism verbatim; if the file is a text file with CR/LF pairs at the end of each line, this will cause some regular expressions to fail. This

option has no effect on platforms other than MS-DOS and MS-Win-

dows.

-uu, --uunniixx-bbyyttee-ooffffsseettss

Report Unix-style byte offsets. This switch causes ggrreepp to

report byte offsets as if the file were Unix-style text file,

i.e. with CR characters stripped off. This will produce results identical to running ggrreepp on a Unix machine. This option has no

effect unless -bb option is also used; it has no effect on plat-

forms other than MS-DOS and MS-Windows.

-VV, --vveerrssiioonn

Print the version number of ggrreepp to standard error. This ver-

sion number should be included in all bug reports (see below).

-vv, --iinnvveerrtt-mmaattcchh

Invert the sense of matching, to select non-matching lines.

-ww, --wwoorrdd-rreeggeexxpp

Select only those lines containing matches that form whole words. The test is that the matching substring must either be

at the beginning of the line, or preceded by a non-word con-

stituent character. Similarly, it must be either at the end of

the line or followed by a non-word constituent character. Word-

constituent characters are letters, digits, and the underscore.

-xx, --lliinnee-rreeggeexxpp

Select only those matches that exactly match the whole line.

-yy Obsolete synonym for -ii.

-ZZ, --nnuullll

Output a zero byte (the ASCII NNUULL character) instead of the character that normally follows a file name. For example, ggrreepp

-llZZ outputs a zero byte after each file name instead of the

usual newline. This option makes the output unambiguous, even in the presence of file names containing unusual characters like newlines. This option can be used with commands like ffiinndd

-pprriinntt00, ppeerrll -00, ssoorrtt -zz, and xxaarrggss -00 to process arbitrary

file names, even those that contain newline characters. RREEGGUULLAARR EEXXPPRREESSSSIIOONNSS A regular expression is a pattern that describes a set of strings.

Regular expressions are constructed analogously to arithmetic expres-

sions, by using various operators to combine smaller expressions. GGrreepp understands two different versions of regular expression syntax:

"basic" and "extended." In GNU ggrreepp, there is no difference in avail-

able functionality using either syntax. In other implementations, basic regular expressions are less powerful. The following description applies to extended regular expressions; differences for basic regular expressions are summarized afterwards. The fundamental building blocks are the regular expressions that match a single character. Most characters, including all letters and digits, are regular expressions that match themselves. Any metacharacter with special meaning may be quoted by preceding it with a backslash. A bracket expression is a list of characters enclosed by [[ and ]]. It matches any single character in that list; if the first character of the list is the caret ^^ then it matches any character not in the list. For example, the regular expression [[00112233445566778899]] matches any single digit.

Within a bracket expression, a range expression consists of two charac-

ters separated by a hyphen. It matches any single character that sorts between the two characters, inclusive, using the locale's collating sequence and character set. For example, in the default C locale,

[[aa-dd]] is equivalent to [[aabbccdd]]. Many locales sort characters in dictio-

nary order, and in these locales [[aa-dd]] is typically not equivalent to

[[aabbccdd]]; it might be equivalent to [[aaBBbbCCccDDdd]], for example. To obtain the traditional interpretation of bracket expressions, you can use the C locale by setting the LLCCAALLLL environment variable to the value CC. Finally, certain named classes of characters are predefined within bracket expressions, as follows. Their names are self explanatory, and they are [[::aallnnuumm::]], [[::aallpphhaa::]], [[::ccnnttrrll::]], [[::ddiiggiitt::]], [[::ggrraapphh::]], [[::lloowweerr::]], [[::pprriinntt::]], [[::ppuunncctt::]], [[::ssppaaccee::]], [[::uuppppeerr::]], and [[::xxddiiggiitt::]]..

For example, [[[[::aallnnuumm::]]]] means [[00-99AA-ZZaa-zz]], except the latter form

depends upon the C locale and the ASCII character encoding, whereas the former is independent of locale and character set. (Note that the brackets in these class names are part of the symbolic names, and must be included in addition to the brackets delimiting the bracket list.) Most metacharacters lose their special meaning inside lists. To include a literal ]] place it first in the list. Similarly, to include a literal ^^ place it anywhere but first. Finally, to include a literal

- place it last.

The period .. matches any single character. The symbol \\ww is a synonym for [[[[::aallnnuumm::]]]] and \\WW is a synonym for [[^^[[::aallnnuumm]]]].

The caret ^^ and the dollar sign $$ are metacharacters that respectively

match the empty string at the beginning and end of a line. The symbols \\<< and \\>> respectively match the empty string at the beginning and end of a word. The symbol \\bb matches the empty string at the edge of a word, and \\BB matches the empty string provided it's not at the edge of a word.

A regular expression may be followed by one of several repetition oper-

ators: ?? The preceding item is optional and matched at most once. ** The preceding item will be matched zero or more times. ++ The preceding item will be matched one or more times. {{n}} The preceding item is matched exactly n times. {{n,,}} The preceding item is matched n or more times. {{n,,m}} The preceding item is matched at least n times, but not more than m times. Two regular expressions may be concatenated; the resulting regular expression matches any string formed by concatenating two substrings that respectively match the concatenated subexpressions. Two regular expressions may be joined by the infix operator ||; the

resulting regular expression matches any string matching either subex-

pression. Repetition takes precedence over concatenation, which in turn takes precedence over alternation. A whole subexpression may be enclosed in parentheses to override these precedence rules. The backreference \\n, where n is a single digit, matches the substring

previously matched by the nth parenthesized subexpression of the regu-

lar expression. In basic regular expressions the metacharacters ??, ++, {{, ||, ((, and )) lose their special meaning; instead use the backslashed versions \\??, \\++, \\{{, \\||, \\((, and \\)). Traditional eeggrreepp did not support the {{ metacharacter, and some eeggrreepp implementations support \\{{ instead, so portable scripts should avoid {{ in eeggrreepp patterns and should use [[{{]] to match a literal {{. GNU eeggrreepp attempts to support traditional usage by assuming that {{ is

not special if it would be the start of an invalid interval specifica-

tion. For example, the shell command eeggrreepp ''{{11'' searches for the two-

character string {{11 instead of reporting a syntax error in the regular expression. POSIX.2 allows this behavior as an extension, but portable scripts should avoid it. For more information see reformat(7). ENVIRONMENT VARIABLES Grep's behavior is affected by the following environment variables.

A locale LLCCfoo is specified by examining the three environment vari-

ables LLCCAALLLL, LLCCfoo, LLAANNGG, in that order. The first of these vari-

ables that is set specifies the locale. For example, if LLCCAALLLL is not set, but LLCCMMEESSSSAAGGEESS is set to ppttBBRR, then Brazilian Portuguese is used for the LLCCMMEESSSSAAGGEESS locale. The C locale is used if none of these environment variables are set, or if the locale catalog is not installed, or if ggrreepp was not compiled with national language support (NLS). GGRREEPPOOPPTTIIOONNSS This variable specifies default options to be placed in front of any explicit options. For example, if GGRREEPPOOPPTTIIOONNSS is

''--bbiinnaarryy-ffiilleess==wwiitthhoouutt-mmaattcchh --ddiirreeccttoorriieess==sskkiipp'', ggrreepp behaves

as if the two options --bbiinnaarryy-ffiilleess==wwiitthhoouutt-mmaattcchh and --ddiirreecc-

ttoorriieess==sskkiipp had been specified before any explicit options. Option specifications are separated by whitespace. A backslash escapes the next character, so it can be used to specify an option containing whitespace or a backslash. GGRREEPPCCOOLLOORR Specifies the marker for highlighting. LLCCAALLLL, LLCCCCOOLLLLAATTEE, LLAANNGG These variables specify the LLCCCCOOLLLLAATTEE locale, which determines the collating sequence used to interpret range expressions like

[[aa-zz]].

LLCCAALLLL, LLCCCCTTYYPPEE, LLAANNGG These variables specify the LLCCCCTTYYPPEE locale, which determines the type of characters, e.g., which characters are whitespace. LLCCAALLLL, LLCCMMEESSSSAAGGEESS, LLAANNGG These variables specify the LLCCMMEESSSSAAGGEESS locale, which determines the language that ggrreepp uses for messages. The default C locale uses American English messages. PPOOSSIIXXLLYYCCOORRRREECCTT If set, ggrreepp behaves as POSIX.2 requires; otherwise, ggrreepp behaves more like other GNU programs. POSIX.2 requires that options that follow file names must be treated as file names; by default, such options are permuted to the front of the operand list and are treated as options. Also, POSIX.2 requires that unrecognized options be diagnosed as "illegal", but since they are not really against the law the default is to diagnose them

as "invalid". PPOOSSIIXXLLYYCCOORRRREECCTT also disables NGGNNUUnnoonnoopp-

ttiioonnaarrggvvffllaaggss, described below. NGGNNUUnnoonnooppttiioonnaarrggvvffllaaggss (Here N is ggrreepp's numeric process ID.) If the ith character of this environment variable's value is 11, do not consider the ith operand of ggrreepp to be an option, even if it appears to be one.

A shell can put this variable in the environment for each com-

mand it runs, specifying which operands are the results of file name wildcard expansion and therefore should not be treated as options. This behavior is available only with the GNU C library, and only when PPOOSSIIXXLLYYCCOORRRREECCTT is not set. DIAGNOSTICS Normally, exit status is 0 if selected lines are found and 1 otherwise.

But the exit status is 2 if an error occurred, unless the -qq or --qquuiieett

or --ssiilleenntt option is used and a selected line is found.

BUGS

Email bug reports to bbuugg-ggnnuu-uuttiillss@@ggnnuu..oorrgg. Be sure to include the

word "grep" somewhere in the "Subject:" field. Large repetition counts in the {{n,,m}} construct may cause grep to use lots of memory. In addition, certain other obscure regular expressions require exponential time and space, and may cause ggrreepp to run out of memory. Backreferences are very slow, and may require exponential time. GNU Project 2002/01/22 GREP(1)




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™