HP-UX Reference (11i v2 07/12) - 1 User Commands A-M (vol 1)

g
grep(1) grep(1)
Ken 112 Warring St. Apt. A
Judy 387 Bowditch Apt. 12
Ann 429 Sixth St.
the command:
grep Judy address
prints:
Judy 387 Bowditch Apt. 12
To search a file for lines that contain either a
Dec or Nov, use either of the following commands:
grep -E ’[Dd]ec|[Nn]ov’
file
egrep -i ’dec|nov’ file
Search all files in the current directory for the string
xyz:
grep xyz *
Search all files in the current directory subtree for the string
xyz, and ensure that no error occurs due to
file name expansion exceeding system argument list limits:
find . -type f -print |xargs grep xyz
The previous example does not print the name of files where string xyz appears. To force
grep to print
file names, add a second argument to the
grep command portion of the command line:
find . -type f -print |xargs grep xyz /dev/null
In this form, the first file name is that produced by find, and the second file name is the null file.
WARNINGS
(XPG4 only.) If the
-q option is specified, the exit status will be zero if an input line is selected, even if an
error was detected. Otherwise, default actions will be performed.
If the -w option is specified with non-word constituent characters, then the output is unexpected.
SEE ALSO
sed(1), sh(1), regcomp(3C), environ(5), lang(5), regexp(5).
STANDARDS CONFORMANCE
grep: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
egrep: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
fgrep: SVID2, SVID3, XPG2, XPG3, XPG4, POSIX.2
HP-UX 11i Version 2: December 2007 Update 3 Hewlett-Packard Company 413