gtpo1m5uOperations

ZFILE grep-Search a File for a Specified Pattern

Use this command to search files for one or more patterns.

Requirements and Restrictions

Format




-c
displays the number of matching lines.

-E
interprets pattern as an extended regular expression.

-i
ignores the case when searching for matching lines.

-l
lists the file names that contain matching lines.

-n
displays the matching lines and the file line number.

-s
suppresses the display of error messages that result from nonexisting or unreadable files.

-v
displays the lines that do not match the specified criteria.

-w
displays the lines that match whole words only.

-x
displays lines only when pattern matches the entire line.

pattern
is the pattern, or regular expression, to use in searching the files.

-e
allows you to specify more than one search pattern, each separated with a -e.

-f patternfile
reads one or more patterns from a file, where patternfile is the path to the file that contains the patterns you are searching for. Pattern strings within patternfile are separated by a new-line character (\n).

path
is the path to the source file whose contents are to be searched.

Additional Information

Examples

In the following example, all files with the .h extension are searched for regular expression T.F.

+--------------------------------------------------------------------------------+
|User:   ZFILE grep T.F *.h                                                      |
|                                                                                |
|System: FILE0001I 08:14:31 START OF DISPLAY FROM grep T.F *.h                   |
|        bytecode.h:		BGET_FREAD(ary, 256, 2);                                   |
|        config.h:/* has_FSTATVFS:                                               |
|        perl.h:#if defined(TPF) && defined(I_SYS_TIMES)                         |
|        END OF DISPLAY                                                          |
|                                                                                |
+--------------------------------------------------------------------------------+

In the following example, all files with the .c extension are searched for patterns TPF and tpf_fork.

+--------------------------------------------------------------------------------+
|User:   ZFILE grep -e TPF -e tpf_fork *.c                                       |
|                                                                                |
|System: FILE0001I 08:14:31 START OF DISPLAY FROM grep -e TPF -e tpf_fork *.c    |
|        pp_sys.c:#ifdef TPF                                                     |
|        tpf.c:   struct tpf_fork_input fork_input;                              |
|        util.c:#if !defined(VMS) && !defined(TPF)                               |
|        END OF DISPLAY                                                          |
+--------------------------------------------------------------------------------+

In the following example, files tpf.c and tpf.h are searched for pattern setenv. Only file tpf.c contains the specified pattern.

+--------------------------------------------------------------------------------+
|User:   ZFILE grep -l setenv tpf.c tpf.h                                        |
|                                                                                |
|System: FILE0001I 08:14:31 START OF DISPLAY FROM grep -l setenv tpf.c tpf.h     |
|        tpf.c                                                                   |
|        END OF DISPLAY                                                          |
+--------------------------------------------------------------------------------+

In the following example, files beginning with either the letter s or the letter t and ending with either the .c or .h extension are searched for pattern print. The options indicate that the file name and the number of times that pattern is in that file will be displayed.

+--------------------------------------------------------------------------------+
|User:   ZFILE grep -c print* [st]*.[ch]                                         |
|                                                                                |
|System: FILE0001I 08:14:31 START OF DISPLAY FROM grep -c print* [st]*.[ch]      |
|        sv.c:119                                                                |
|        sv.h:0                                                                  |
|        taint.c:0                                                               |
|        tpf.c:2                                                                 |
|        END OF DISPLAY                                                          |
+--------------------------------------------------------------------------------+

In the following example, all files are searched for pattern has_fork. The -i parameter indicates that the case in the pattern will be ignored.

+--------------------------------------------------------------------------------+
|User:   ZFILE grep -i has_fork *                                                |
|                                                                                |
|System: FILE0001I 08:14:31 START OF DISPLAY FROM grep -i has_fork *             |
|        util.c:#ifdef HAS_FORK                                                  |
|        END OF DISPLAY                                                          |
+--------------------------------------------------------------------------------+

In the following example, file util.c is searched for patterns listed on separate lines in file file1. For this example, file1 contains the following:

TPF
HAS_FORK
+--------------------------------------------------------------------------------+
|User:   ZFILE grep -f file1 util.c                                              |
|                                                                                |
|System: FILE0001I 08:14:31 START OF DISPLAY FROM grep -f file1 util.c           |
|        #if !defined(VMS) && !defined(TPF)  /* VMS' my_setenv() is in VMS.c */  |
|        #if (!defined(DOSISH) || defined(HAS_FORK)                              |
|        END OF DISPLAY                                                          |
+--------------------------------------------------------------------------------+

Related Information

See Information Technology--Portable Operating System Interface for Computer Environments (POSIX) for more information about the POSIX standards.