[Top] [Prev] [Next] [Bottom]
grep - search file(s) for a pattern
grep [-l] [-n] [-e pattern] [-v] pattern [file... ]
Description
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
Options
-l
|
Print once the names of files with any matching lines. Matched lines are not printed.
|
-n
|
Prefix each line of output with its line number within its file.
|
-v
|
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] [Bottom]
infernosupport@lucent.com
Copyright © 1997, Lucent Technologies, Inc.. All rights
reserved.