SEARCH
NEW RPMS
DIRECTORIES
ABOUT
FAQ
VARIOUS
BLOG

BotDetect - Real-Time Bot Detection API
 
 

MAN page from Old RedHat 5.X grep-2.3-1.i386.rpm

GREP

Section: User Commands (1)
Updated: 1998/11/22
Index 

NAME

grep, egrep, fgrep - print lines matching a pattern 

SYNOPSIS

grep[-[AB] NUM] [-CEFGVabchiLlnqrsvwxyUu] [-e PATTERN | -f FILE][-d ACTION] [--directories=ACTION][--extended-regexp] [--fixed-strings] [--basic-regexp][--regexp=PATTERN] [--file=FILE] [--ignore-case] [--word-regexp][--line-regexp] [--line-regexp] [--no-messages] [--revert-match][--version] [--help] [--byte-offset] [--line-number][--with-filename] [--no-filename] [--quiet] [--silent] [--text][--files-without-match] [--files-with-matcces] [--count][--before-context=NUM] [--after-context=NUM] [--context][--binary] [--unix-byte-offsets] [--recursive]files... 

DESCRIPTION

Grepsearches the named inputfiles(or standard input if no files are named, orthe file name-is given)for lines containing a match to the givenpattern.By default,grepprints the matching lines.

There are three major variants ofgrep,controlled by the following options.

-G, --basic-regexp
Interpretpatternas a basic regular expression (see below). This is the default.
-E, --extended-regexp
Interpretpatternas an extended regular expression (see below).
-F, --fixed-strings
Interpretpatternas a list of fixed strings, separated by newlines,any of which is to be matched.

In addition, two variant programsegrepandfgrepare available.Egrepis similar (but not identical) togrep -E,and is compatible with the historical Unixegrep.Fgrepis the same asgrep -F.

All variants ofgrepunderstand the following options:

-A NUM, --after-context=NUM
PrintNUMlines of trailing context after matching lines.
-B NUM, --before-context=NUM
PrintNUMlines of leading context before matching lines.
-C--context[=NUM]
Print NUMlines (default 2) of output context.
-NUM 
Same as --context=NUM lines of leading and trailing context. However,grepwill never print any given line more than once.
-V, --version
Print the version number ofgrepto standard error. This version number shouldbe included in all bug reports (see below).
-b, --byte-offset
Print the byte offset within the input file beforeeach line of output.
-c, --count
Suppress normal output; instead print a count ofmatching lines for each input file.With the-v, --revert-matchoption (see below), count non-matching lines.
-d ACTION, --directories=ACTION
If an input file is a directory, useACTIONto process it. By default,ACTIONisread,which means that directories are read just as if they were ordinary files.IfACTIONisskip,directories are silently skipped.IfACTIONisrecurse,grep reads all files under each directory, recursively;this is equivalent to the-roption.
-e PATTERN, --regexp=PATTERN
UsePATTERNas the pattern; useful to protect patterns beginning with-.
-f FILE, --file=FILE
Obtain patterns fromFILE,one per line.The empty file contains zero patterns, and therfore matches nothing.
-h, --no-filename
Suppress the prefixing of filenames on outputwhen multiple files are searched.
-i, --ignore-case
Ignore case distinctions in both thepatternand the input files.
-L, --files-without-match
Suppress normal output; instead print the nameof each input file from which no output wouldnormally have been printed. The scanning will stopon the first match.
-l, --files-with-matches
Suppress normal output; instead printthe name of each input file from which outputwould normally have been printed. The scanning willstop on the first match.
-n, --line-number
Prefix each line of output with the line numberwithin its input file.
-q, --quiet, --silent
Quiet; suppress normal output. The scanning will stopon the first match.Also see the-sor--no-messagesoption below.
-r, --recursive
Read all files under each directory, recursively;this is equivalent to the-d recurseoption.
-s, --no-messages
Suppress error messages about nonexistent or unreadable files.Portability note: unlike GNUgrep,BSDgrepdoes not comply with POSIX.2, because BSDgreplacks a-qoption and its-soption behaves like GNUgrep's-qoption.Shell scripts intended to be portable to BSDgrepshould avoid both-qand-sand should redirect output to /dev/null instead.
-a, --text
Do not suppress output lines that contain binary data.Normally, if the first few bytes of a file indicate thatthe file contains binary data,grepoutputs only a message saying that the file matches the pattern.This option causesgrepto act as if the file is a text file,even if it would otherwise be treated as binary.
-v, --revert-match
Invert the sense of matching, to select non-matching lines.
-w, --word-regexp
Select only those lines containing matches that form whole words.The test is that the matching substring must either be at thebeginning of the line, or preceded by a non-word constituentcharacter. Similarly, it must be either at the end of the lineor followed by a non-word constituent character. Word-constituentcharacters are letters, digits, and the underscore.
-x, --line-regexp
Select only those matches that exactly match the whole line.
-y
Obsolete synonym for-i.
-U, --binary
Treat the file(s) as binary. By default, under MS-DOS and MS-Windows,grepguesses the file type by looking at the contents of the first 32KBread from the file. Ifgrepdecides the file is a text file, it strips the CR characters from theoriginal file contents (to make regular expressions with^and$work correctly). Specifying-Uoverrules this guesswork, causing all files to be read and passed to thematching mechanism verbatim; if the file is a text file with CR/LFpairs at the end of each line, this will cause some regularexpressions to fail. This option is only supported on MS-DOS andMS-Windows.
-u, --unix-byte-offsets
Report Unix-style byte offsets. This switch causesgrepto report byte offsets as if the file were Unix-style text file, i.e. withCR characters stripped off. This will produce results identical to runninggrepon a Unix machine. This option has no effect unless-boption is also used; it is only supported on MS-DOS and MS-Windows.
 

REGULAR EXPRESSIONS

A regular expression is a pattern that describes a set of strings.Regular expressions are constructed analogously to arithmeticexpressions, by using various operators to combine smaller expressions.

Grepunderstands two different versions of regular expression syntax:``basic'' and ``extended.'' InGNU grep,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 expressions that matcha single character. Most characters, including all letters and digits,are regular expressions that match themselves. Any metacharacter withspecial meaning may be quoted by preceding it with a backslash.

A list of characters enclosed by[and]matches any singlecharacter in that list; if the first character of the listis the caret^then it matches any characternotin the list.For example, the regular expression[0123456789]matches any single digit. A range of ASCII charactersmay be specified by giving the first and last characters, separatedby a hyphen.Finally, certain named classes of characters are predefined.Their names are self explanatory, and they are[:alnum:],[:alpha:],[:cntrl:],[:digit:],[:graph:],[:lower:],[:print:],[:punct:],[:space:],[:upper:],and[:xdigit:].For example,[[:alnum:]]means[0-9A-Za-z],except the latter 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 symbolicnames, and must be included in addition to the brackets delimitingthe bracket list.) Most metacharacters lose their special meaninginside 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\wis a synonym for[[:alnum:]]and\Wis a synonym for[^[:alnum]].

The caret^and the dollar sign$are metacharacters that respectively match the empty string at thebeginning and end of a line.The symbols\<and\>respectively match the empty string at the beginning and end of a word.The symbol\bmatches the empty string at the edge of a word,and\Bmatches the empty string provided it'snotat the edge of a word.

A regular expression 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 or more times.
+
The preceding item will be matched one or more times.
{n}
The preceding item is matched exactlyntimes.
{n,}
The preceding item is matchednor more times.
{,m}
The preceding item is optional and is matched at mostmtimes.
{n,m}
The preceding item is matched at leastntimes, but not more thanmtimes.

Two regular expressions may be concatenated; the resultingregular expression matches any string formed by concatenatingtwo substrings that respectively match the concatenatedsubexpressions.

Two regular expressions may be joined by the infix operator|;the resulting regular expression matches any string matchingeither subexpression.

Repetition takes precedence over concatenation, which in turntakes precedence over alternation. A whole subexpression may beenclosed in parentheses to override these precedence rules.

The backreference\n, wherenis a single digit, matches the substringpreviously matched by thenthparenthesized subexpression of the regular expression.

In basic regular expressions the metacharacters?,+,{,|,(,and)lose their special meaning; instead use the backslashedversions\?,\+,\{,\|,\(,and\).

Inegrepthe metacharacter{loses its special meaning; instead use\{. 

DIAGNOSTICS

Normally, exit status is 0 if matches were found,and 1 if no matches were found. (The-voption inverts the sense of the exit status.)Exit status is 2 if there were syntax errorsin the pattern, inaccessible input files, orother system errors. 

BUGS

Email bug reports tobug-gnu-utilsAATTgnu.org.Be sure to include the word ``grep'' somewhere in the ``Subject:'' field.

Large repetition counts in the{m,n}construct may cause grep to use lots of memory.In addition,certain other obscure regular expressions require exponential timeand space, and may causegrepto run out of memory.

Backreferences are very slow, and may require exponential time.


 

Index

NAME
SYNOPSIS
DESCRIPTION
REGULAR EXPRESSIONS
DIAGNOSTICS
BUGS

This document was created byman2html,using the manual pages.
 
ICM Bot detect detector