Hitachi

Job Management Partner 1 Version 10 Job Management Partner 1/Advanced Shell Description, User's Guide, Reference, and Operator's Guide


egrep command (searches for characters in files)

Organization of this page

Format

egrep[-a][-b][-c][-E][-h][-I][-i][-L][-l][-n]
     [-q][-R][-r][-s][-U][-v][-w][-x]
     [-A number] [-B number] [-C[number]]
     [-e pattern] [-f pattern-file-path-name] [pattern] [path-name ...]

Description

This command searches files for specified patterns. The patterns to be retrieved are assumed to be extended regular expressions. The behavior of the egrep command is the same as that of the grep command with the -E option specified.

Arguments

-a

Specifies that all files are to be handled as ASCII text files.

-b

Specifies that the offset in bytes is to be displayed at the beginning of each matching line.

-c

Specifies that only the number of lines selected is to be output to the standard output.

-E

Specifies that the value specified in pattern is to be handled as an extended regular expression (default value).

-h

Specifies that no file name is to be displayed at the beginning of each output line when either of the following conditions is satisfied:

  • The -R or -r option is specified.

  • Multiple path names are specified as being subject to search.

-I

Specifies that binary files are to be ignored.

-i

Specifies that uppercase letters are not to be distinguished from lowercase letters (and vice versa).

-L

Specifies that only the names of files that do not contain a match for the value specified in pattern are to be output to the standard output. If the -L and -l options are both specified, the one specified last takes effect.

-l

Specifies that only the names of files that contain a match for the value specified in pattern are to be output to the standard output. If the -L and -l options are both specified, the one specified last takes effect.

-n

Specifies that its relative line number in the file is to be output at the beginning of each output line. This specification is ignored when any of the -c, -L, -l, and -q options is specified.

-q

Specifies that nothing is to be output to the standard output. The command returns only the return code.

-R|-r

Specifies that directories are to be searched recursively.

If the -L, -l, and -q options are all omitted, the file name is output at the beginning of each output line.

-s

Specifies that unreadable or nonexistent files are to be ignored, and output of error messages related to unreadable or nonexistent files is to be suppressed.

-U

Specifies that binary files are to be searched but not output.

-v

Specifies that lines that do not contain a match for the value in pattern are to be output.

-w

Specifies that only lines that contain the specified character string as a whole word are to be output.

A word is a character string that consists of alphanumeric characters and the underscore (_). Words must be delimited by the space, any other non-word character, or the beginning or end of the line.

-x

Specifies that the specified character string is to be compared to each line in the file, and a line is to be output only if the entire line constitutes an exact match.

-A number

Specifies that as many lines as specified that follow a line matching pattern are to be output.

-B number

Specifies that as many lines as specified that precede a line matching pattern are to be output.

-C[number]

Specifies that as many lines as specified that precede and follow a line matching pattern are to be output. If no value is specified (number is omitted), two lines preceding and following a line matching pattern are output. This would be the equivalent of specifying -A 2 -B 2.

If you specify number in the -C option, do not specify any spaces between -C and number.

-e pattern

Used to specify a pattern that begins with a hyphen (-).

-f pattern-file-path-name

Specifies the path name for a file that contains patterns to be searched for. The specified file specifies one line per pattern. If an empty file is specified (a file in which no patterns are specified), there will be nothing to search for and no matches will be found.

pattern

Specifies a pattern to be searched for.

path-name ...

Specifies a path name that is to be searched. Multiple path names can be specified. If no path name is specified, the contents of the standard input are searched. If you specify a directory name, you must also specify the -R or -r option.

If the -L, -l, and -q options are all omitted, the file name is output at the beginning of each output line.

Return code

Return code

Meaning

0

Normal termination.

  • A line was found that contains a pattern being searched for.

  • Or, if the -v option is specified, a line was found that does not contain the pattern being searched for.

1

Normal termination.

  • No lines contain the pattern being searched for.

  • Or, if the -v option is specified, all lines contain the pattern being searched for.

2 or greater

Error termination

Notes

Usage examples

These usage examples show searches using extended regular expressions. For examples of the options, see the usage examples for the grep command.