grep(1)

 

 

 

grep(1)

NAME

 

 

 

 

grep, egrep, fgrep - search a ®le for a pattern

 

 

SYNOPSIS

 

 

 

 

Plain call with pattern

 

 

 

grep [-E -F]

[-c-l-q]

[-bhinsvwx]

pattern [ ®le

... ]

Call with (multiple) e pattern

 

 

grep [-E -F]

[-c-l-q]

[-bhinsvwx]

-epattern ...

[-epattern ] ... [ ®le ... ]

Call with f ®le

 

 

 

 

grep [-E -F]

[-c-l-q]

[-bhinsvwx]

[-fpattern_ ®le ] [ ®le ... ]

Obsolescent:

egrep [-cefilnsv] [ expression ] [ ®le ... ]

fgrep [-cefilnsvx] [ strings ] [ ®le ... ]

DESCRIPTION

The grep command searches the input text ®les (standard input default) for lines matching a pattern. Normally, each line found is copied to the standard output. grep supports the Basic Regular Expression syntax (see regexp(5)). The -Eoption (egrep) supports Extended Regular Expression (ERE) syntax (see regexp(5)). The -Foption (fgrep) searches for ®xed strings using the fast Boyer-Moore string searching algorithm. The -Eand -Foptions treat newlines embedded in the pattern as alternation characters. A null expression or string matches every line.

The forms egrep and fgrep are maintained for backward compatibility. The use of the -Eand -Foptions is recommended for portability.

Options

Extended regular expressions. Each pattern speci®ed is a sequence of one or

-E

 

more EREs. The EREs can be separated by newline characters or given in

 

separate -eexpression options. A pattern matches an input line if any ERE in

 

the sequence matches the contents of the input line without its trailing newline

 

character. The same functionality is obtained by using egrep.

 

-F

Fixed strings. Each

pattern speci®ed is a sequence of one

or more strings.

 

Strings can be separated by newline characters or given in separate -eexpres-

 

sion options. A pattern matches an input line if the line contains any of the

 

strings in the sequence. The same functionality is obtained by using fgrep.

-b

Each line is preceded by the block number on which it was found. This is useful

 

in locating disk block numbers by context. Block numbers are calculated by

 

dividing by 512 the number of bytes that have been read from the ®le and round-

 

ing down the result.

 

 

-c

Only a count of matching lines is printed.

 

-eexpression

Same as a simple expression argument, but useful when the expression begins

 

with a hyphen (-). Multiple -eoptions can be used to specify multiple patterns;

 

an input line is selected if it matches any of the speci®ed patterns.

-fpattern_ file

The regular expression (grep and grep -E) or strings list (grep -F) is taken

 

from the pattern_ ®le.

 

 

-h

Suppress printing of ®lenames when searching multiple ®les.

 

-i

Ignore uppercase/lowercase distinctions during comparisons.

 

-l

Only the names of ®les with matching lines are listed (once), separated by new-

 

lines. If standard input is searched, a path name of (standard input) will

 

be written, in the POSIX locale. In other locales, (standard

input) may be

 

replaced by something more appropriate in those locales.

 

-n

Each line is preceded by its relative line number in the ®le starting at 1. The

 

line number is reset for each ®le searched. This option is ignored if -c, -b, -l,

 

or -qis speci®ed.

 

 

HP-UX Release 11i: December 2000

− 1 −

Section 1339

g