Hitachi

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


grep command (searches for characters in files)

Organization of this page

Format

grep [-a] [-b] [-c] [-E] [-G] [-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 characters (specified in pattern).

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. When the -E and -G options are both specified, the one specified last takes effect.

-G

Specifies that the value specified in pattern is to be handled as a regular expression. This is the default behavior. When the -E and -G options are both specified, the one specified last takes effect.

-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 name 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.

-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 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), the default is 2 (which 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 codes

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