PGREP(1P)
NAME
pgrep − search files in a project hierarchy for a pattern
SYNOPSIS
pgrep [−eilmnw] [−f makefile] [−C command] [−F patfile] [−P pdirname] [−T typexpr] [pattern [file ...]]
DESCRIPTION
Pgrep searchs through the files in a project hierarchy for lines matching pattern. Normally, each line found is printed to standard output. Alternatively, a command can be executed in each project directory, with arguments that are the names of files containing pattern.
The names of files can be specified as arguments, or obtained from the ‘HDRS’ and ‘SRCS’ macro definitions in a makefile (−m option), or a combination of both. When pgrep is told to use a makefile and the −f option is not present, the files ‘makefile’ and ‘Makefile’ are tried in order.
Pgrep uses pexec to execute either the grep or egrep commands over a project hierarchy. Grep patterns are limited to regular expressions in the style of ex(1). Egrep patterns are full regular expressions. Care should be taken when using the characters $ * [ | ( ) and \ in pattern as they are also meaningful to the command shell. It is safest to enclose the entire pattern in single quotes.
OPTIONS
−eUse egrep instead of grep.
−f makefile
Specify an alternative makefile file name. This option also implies the −m option.
−iIgnore case of letters when making comparisons (i.e. upper and lower case are considered identical). Grep only.
−lList the names of files with matching lines. The file names are printed one per line.
−mObtain the names of files to search from a makefile. If no −f option is present, the makefiles ‘makefile’ and ‘Makefile’ are tried in order.
−nPrecede each matching line by its relative line number in the file.
−wTreat pattern as a word (i.e. as if surrounded by ‘\<’ and ‘\>’; see ex(1)). Grep only.
−C command
Execute command in each project directory, with arguments that are the names of files containing pattern.
−F patfile
The regular expression is taken from patfile. Egrep only.
−P pdirname
Specify a project other than the current working project. If pdirname is a project directory, search files in that directory only.
−T typexpr
Only search files in project directories corresponding to boolean type label expression, typexpr.
EXAMPLES
If all the directories in a project that contain source code have been labeled previously as type ‘src’, then, to search all the source code makefiles for the pattern ‘VERSION =’, type:
pgrep −Tsrc ´VERSION.*=´ Makefile
where quotes surround the pattern to prevent file name expansion in the current directory.
To edit all the source code files that contain the pattern ‘open(’ using the vi editor, type:
pgrep −m −Cvi −Tsrc ´open(´
where −m tells pgrep to get the names of the source code files from a makefile.
FILES
makefileDefault makefile.
MakefileAlternative default makefile.
SEE ALSO
egrep(1), ex(1), grep(1), make(1), mkmf(1P), pexec(1P), pgrep(3P), vi(1)
DIAGNOSTICS
Exit status is 0 if any matches are found, 1 if none, 2 for syntax errors or inaccessible files and directories.
AUTHOR
Peter J. Nicklin