g

grep(1)

grep(1)

-q

(Quiet) Do not write anything to the standard output, regardless of matching

 

lines. Exit with zero status upon ®nding the ®rst matching line. Overrides any

 

options that would produce output.

-s

Error messages produced for nonexistent or unreadable ®les are suppressed.

-v

All lines but those matching are printed.

-w

Select only those lines containing matches that form whole words. The test is

 

that the matching substring must either be at the beginning of the line, or pre-

 

ceded by a non-word constituent character. Similarly, it must be either at the

 

end of the line or followed by a non-word constituent character. Word-constituent

 

characters are letters, digits, and the underscore.

-x

(eXact) Matches are recognized only when the entire input line matches the ®xed

 

string or regular expression.

The ®le name is output in all the cases in which output is generated if there are more than one input ®le, unless the -h option is speci®ed. Care should be taken when using the characters $, *, [, Ã, , (, ), and \ in expression, because they are also meaningful to the shell. It is safest to enclose the entire expression argument in single quotes ('...').

EXTERNAL INFLUENCES

Environment Variables

LANG determines the locale to use for the locale categories when both LC_ALL and the corresponding environment variable (beginning with LC_) do not specify a locale. If LANG is not speci®ed or is set to the empty string, a default of C (see lang(5)) is used.

LC_ALL determines the locale to use to override any values for locale categories speci®ed by the settings of LANG or any environment variables beginning with LC_.

LC_COLLATE determines the collating sequence used in evaluating regular expressions.

LC_CTYPE determines the interpretation of text as single byte and/or multi-byte characters, the classi®cation of characters as letters, the case information for the -ioption, and the characters matched by character class expressions in regular expressions.

LC_MESSAGES determines the language in which messages are displayed.

If any internationalization variable contains an invalid setting, the commands behave as if all internationalization variables are set to C. See environ(5).

International Code Set Support

Single-byte and multi-byte character code sets are supported.

RETURN VALUE

Upon completion, grep returns one of the following values:

0One or more matches found.

1No match found.

2Syntax error or inaccessible ®le (even if matches were found).

EXAMPLES

In the Bourne shell (sh(1)) the following example searches two ®les, ®nding all lines containing occurrences of any of four strings:

grep -F 'if then

else

fi' ®le1 ®le2

Note that the single quotes are necessary to tell grep -Fwhen the strings have ended and the ®le names have begun.

For the C shell (see csh(1)) the following command can be used:

grep -F 'if\ then\ else\ fi' ®le1 ®le2

To search a ®le named address containing the following entries:

Section 1340

− 2 −

HP-UX Release 11i: December 2000