home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Fresh Fish 8
/
FreshFishVol8-CD1.bin
/
gnu
/
man
/
cat1
/
grep.0
< prev
next >
Wrap
Text File
|
1993-12-07
|
11KB
|
265 lines
GREP(1) GREP(1)
NNAAMMEE
grep, egrep, fgrep - print lines matching a pattern
SSYYNNOOPPOOSSIISS
ggrreepp [ --[[AABB] ]_n_u_m ] [ --[CCEEFFGGVVBBcchhiillnnssvvwwxx] ] [ --ee ] _p_a_t_t_e_r_n
| --ff_f_i_l_e ] [ _f_i_l_e_s_._._. ]
DDEESSCCRRIIPPTTIIOONN
GGrreepp searches the named input _f_i_l_e_s (or standard input if
no files are named, or the file name -- is given) for lines
containing a match to the given _p_a_t_t_e_r_n. By default, ggrreepp
prints the matching lines.
There are three major variants of ggrreepp, controlled by the
following options.
--GG Interpret _p_a_t_t_e_r_n as a basic regular expression
(see below). This is the default.
--EE Interpret _p_a_t_t_e_r_n as an extended regular expression
(see below).
--FF Interpret _p_a_t_t_e_r_n as a list of fixed strings, sepa-
rated by newlines, any of which is to be matched.
In addition, two variant programs eeggrreepp and ffggrreepp are
available. EEggrreepp is similiar (but not identical) to
ggrreepp --EE, and is compatible with the historical Unix eeggrreepp.
FFggrreepp is the same as ggrreepp --FF.
All variants of ggrreepp understand the following options:
--_n_u_m Matches will be printed with _n_u_m lines of leading
and trailing context. However, ggrreepp will never
print any given line more than once.
--AA _n_u_m Print _n_u_m lines of trailing context after matching
lines.
--BB _n_u_m Print _n_u_m lines of leading context before matching
lines.
--CC Equivalent to --22.
--VV Print the version number of ggrreepp to standard error.
This version number should be included in all bug
reports (see below).
--bb Print the byte offset within the input file before
each line of output.
--cc Suppress normal output; instead print a count of
matching lines for each input file. With the --vv
option (see below), count non-matching lines.
--ee _p_a_t_t_e_r_n
Use _p_a_t_t_e_r_n as the pattern; useful to protect pat-
terns beginning with --.
--ff _f_i_l_e
Obtain the pattern from _f_i_l_e.
--hh Suppress the prefixing of filenames on output when
multiple files are searched.
--ii Ignore case distinctions in both the _p_a_t_t_e_r_n and
the input files.
--LL Suppress normal output; instead print the name of
each input file from which no output would normally
GNU Project 1992 September 10 1
GREP(1) GREP(1)
have been printed.
--ll Suppress normal output; instead print the name of
each input file from which output would normally
have been printed.
--nn Prefix each line of output with the line number
within its input file.
--qq Quiet; suppress normal output.
--ss Suppress error messages about nonexistent or
unreadable files.
--vv Invert the sense of matching, to select non-
matching lines.
--ww 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 constituent charac-
ter. Similarly, it must be either at the end of
the line or followed by a non-word constituent
character. Word-constituent characters are let-
ters, digits, and the underscore.
--xx Select only those matches that exactly match the
whole line.
RREEGGUULLAARR EEXXPPRREESSSSIIOONNSS
A regular expression is a pattern that describes a set of
strings. Regular expressions are constructed analagously
to arithmetic expressions, by using various operators to
combine smaller expressions.
GGrreepp understands two different versions of regular expres-
sion syntax: ``basic'' and ``extended.'' In GNU ggrreepp,
there is no difference in available 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 expres-
sions 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 list of characters enclosed by [[ and ]] matches any sin-
gle character in that list; if the first character of the
list is the caret ^^ then it matches any character _n_o_t in
the list. For example, the regular expression
[[00112233445566778899]] matches any single digit. A range of ASCII
characters may be specified by giving the first and last
characters, separated by a hyphen. Finally, certain named
classes of characters are predefined. 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
GNU Project 1992 September 10 2
GREP(1) GREP(1)
form is dependent upon the ASCII character encoding,
whereas the former is portable. (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 lit-
eral -- 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 _n_o_t at the
edge of a word.
A regular expression matching a single character may be
followed by one of several repetition operators:
?? The preceding item is optional and matched at most
once.
** The preceding item will be matched zero o