[Top] [Prev] [Next]

grep - search file(s) for a pattern

grep [-l] [-n] [-e pattern] [-v] pattern [file... ]


The grep command searches the input files (standard input, by default) for lines that match the pattern, a regular expression as defined in regex. Lines matching the pattern ('matching' lines) are printed to the standard output.

The minus (' - ') sign can be used on the command line to explicitly name standard input as an input source. The following command will search file1, then standard input, then file2.

	grep pattern file1 - file2


Print once the names of files with any matching lines. Matched lines are not printed.


Prefix each line of output with its line number within its file.


Reverse: print lines that do not match the pattern.

-e pattern

Use the following field as the pattern for selecting lines. Handy when searching for patterns that might be interpreted as options. The following command searches for instances of -n in file.

grep -e -n file

See Also

regex - regular expression recognizer in Chapter 15

[Top] [Prev] [Next]

Copyright © 1996,Lucent Technologies, Inc. All rights reserved.