Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ egrep(1) — SunOS 0.3

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ex(1)

sed(1)

sh(1)

GREP(1)  —  User’s Manual — Commands

NAME

grep, egrep, fgrep − search a file for a pattern

SYNOPSIS

grep [ −v ] [ −c ] [ −l ] [ −n ] [ −b ] [ −i ] [ −s ] [ −w ] [ −eexpression ] expression [ file ] ...

egrep [ −v ] [ −c ] [ −l ] [ −n ] [ −b ] [ −s ] [ −eexpression ] [ −ffile ] [ expression ] [ file ] ...

fgrep [ −v ] [ −x ] [ −c ] [ −l ] [ −n ] [ −b ] [ −i ] [ −s ] [ −eexpression ] [ −ffile ]

[ strings ] [ file ] ...

DESCRIPTION

Commands of the grep family search the input files (standard input default) for lines matching a pattern.  Normally, each line found is copied to the standard output.  Grep patterns are limited regular expressions in the style of ex(1). Egrep patterns are full regular expressions including alternation.  Fgrep patterns are fixed strings — no regular expression metacharacters are supported. 

In all cases the file name is displayed if there is more than one input file.  Care should be taken when using the characters $ ∗ [ ^ | ( ) and \ in the expression as they are also meaningful to the Shell.  It is safest to enclose the entire expression argument in single quotes ´ ´. 

Fgrep searches for lines that contain one of the (newline-separated) strings. 

Egrep accepts extended regular expressions. 

OPTIONS

−v Invert the search to only display lines that do not match. 

−x Display only those lines which match exactly — that is, only lines which match in their entirety (fgrep only). 

−c Display a count of matching lines. 

−l List the names of files with matching lines (once) separated by newlines. 

−n Precede each line by its relative line number in the file. 

−b Precede each line by the block number on which it was found.  This is sometimes useful in locating disk block numbers by context. 

−i Ignore the case of letters in making comparisons — that is, upper and lower case are considered identical.  This applies to grep and fgrep only. 

−s Work silently, that is, display nothing except error messages.  This is useful for checking the error status. 

−w search for the expression as a word as if surrounded by ‘\<’ and ‘\>’, see ex(1). grep only.

−e expression
Same as a simple expression argument, but useful when the expression begins with a −. 

−f file Take the regular expression (egrep) or string list (fgrep) from file. 

REGULAR EXPRESSIONS

In the following description ‘character’ excludes newline:

\Is an escape character: \ followed by any single character other than newline matches that character. 

^Anchored match: matches the beginning of a line. 

$Anchored match: matches the end of a line. 

.(period) matches any character. 

cWhere c is any single character not otherwise endowed with special meaning matches that character. 

[string]
Character class: match any single character from string.  Ranges of ASCII character codes may be abbreviated as in ‘a−z0−9’.  A ] may occur only as the first character of the string.  A literal − must be placed where it can’t be mistaken as a range indicator.  A ^ (circumflex) character immediately after the open bracket negates the sens of the character class, that is, the pattern matches any character except those in the character class. 

∗Closure: a regular expression followed by an ∗ (asterisk) matches a sequence of 0 or more matches of the regular expression. 

+Closure: a regular expression followed by a + (plus) matches a sequence of 1 or more matches of the regular expression. 

?Closure: a regular expression followed by a ? (question mark) matches a sequence of 0 or 1 matches of the regular expression. 

concatenation
Two regular expressions concatenated match a match of the first followed by a match of the second.

|Alternation: two regular expressions separated by | or newline match either a match for the first or a match for the second (egrep only). 

()A regular expression enclosed in parentheses matches a match for the regular expression. 

The order of precedence of operators at the same parenthesis level is [ ] (character classes), then ∗ + ? (closures), then concatenation, then | (alternation) and newline. 

EXAMPLES

Search a file for a fixed string using fgrep:

% fgrep  intro  /usr/man/man3/∗.3∗

Look for character classes using grep:

% grep  ’[1-8]([CJMSNX])’  /usr/man/man1/∗.1

Look for alternative patterns using egrep:

% egrep  ’(Sally|Fred) (Smith|Jones|Parker)’  telephone.list

SEE ALSO

ex(1), sed(1), sh(1)

DIAGNOSTICS

Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files.  This message appears when the list of strings to serach for is being read from a file, and there are too many words for fgrep to handle. 

BUGS

Lines are limited to 256 characters; longer lines are truncated. 

Ideally there should be only one grep, but for historical reasons there are three different versions each with a slightly different set of options and syntaxes. 

Sun System Release 0.3  —  26 April 1983

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026