The Graham Utilities for OS/2 - Version 2


[Warpspeed]

[Table of Contents] [Index] [Previous] [Next]


GREP - Text search utility

Summary

GREP is a simple text search utility. It searches for the specified pattern of text in the files specified.

Icon

Command Line Format

Usage: GREP {Switches} <Pattern> File Spec Drive Spec(s)

Switches

-a
All disks.
-c
Show the matched characters in Colour.
-f
List the File name.
-h
Hard disks only.
-i
Make the pattern case Insensitive.
-n
List the line Number.
-o
Only list the file name.
-s
Subdirectories.
-x
List the lines which do NOT have the pattern in them.

Description

GREP is a simple text search utility. It searches for the specified pattern of text in the files specified. GREP can also be used as a filter - which means that the output from another file or program can be redirected or piped into GREP for it to scan.

This implementation of GREP is more of a FGREP, in that it only does simple text sub string searches - not full regular expression parsing. A full General Regular Expression Parser may be available in a future release.

-a All disks

GREP will scan all logical disk drives defined by the system, starting at drive A:. The drives are scanned in order, starting at A:, then B: and so on.

-c Show the matched characters in Colour

By default, GREP simply displays the line of text on which the pattern match occurred. This switch forces GREP to display the search pattern in green text. It then resets the colour to normal, low intensity white.

-f List the File name

Normally GREP does not display the file name of the file in which the match occurred. This switch displays the file name. It is particularly useful when GREP is used with multiple files (wild cards).

-h Hard disks only

GREP will scan all logical disk drives defined by the system, starting at drive C:. The drives are scanned in order, starting at C:, then D: and so on.

-i Make the pattern case Insensitive

By default, GREP's pattern searches are case sensitive. This switch makes the pattern matches case insensitive. Therefore, with this switch GREP will match the pattern "The" in lines containing "the", "THE", "The" and so on.

-n List the line Number

GREP will display the line number (beginning at one) on which the pattern match occurred.

-o Only list the file name

This option forces GREP to only display the file name of any file which matches the given pattern. This option has precedence over the other options.

-s Subdirectories

GREP will include subdirectories as part of its search of the specified disk drives. If a subdirectory name is included as part of the file specification, then the search will include that subdirectory and all subdirectories below it. If no subdirectory is given as part of the file specification, then the current directory and all below it are included in the search.

-x List the lines that do Not have pattern in them

This switch will force GREP to display every line which does NOT have the pattern in them.

Examples

GREP -finc REM C:\CONFIG.SYS
If a match is found GREP will display the file name, the line number and any line which has "REM" in it. The pattern search is case insensitive, and the pattern "REM" will be displayed in colour.
GREP -fincs LOGON C:\*.CMD
GREP will search all .CMD files on drive C: only. It will display the file name, line number, and the case insensitive pattern in colour of any lines which have LOGON in them.
GREP -x Test C:\TEST.DAT
This will force GREP to display all lines in TEST.DAT which do NOT have the pattern "Test" in them.
DIR | GREP -i .EXE
This is an example of how GREP can be used as a filter. GREP takes the output of the DIR command and will only display those lines with .EXE in them.
DIR | GREP -i .EXE | GREP 12-03-94
GREP may be used as a filter multiple times. This example is the same as the above example, but the second invocation of GREP will modify the output so that only .EXE files dated 12-03-94 will be displayed.
DIR | GREP -i .EXE | GREP -x 12-03-94
This example is similar to the above, except that it will list all .EXE files which are not dated 12-03-94.
GREP -fincs SYS H:\FILES.BBS | GREP -ic INFO
This will force GREP to list all lines with both SYS and INFO in them. All FILES.BBS files on drive H: will be searched.

This is an example of how GREP can search for multiple keywords within the one line. GREP will report on any line with SYS and INFO in them. The order is not important. It will find matches in and display the following lines:

OPSYS_.LZH   (   )OPSYS: DOS / OS/2 Utility that informs
SYSLEVEL.LZH (   )Contains format info for the syslevel file
SYSINFO.LZH  (   )*** Needs to be described
CNFGSORT.LZH (   )Information file to edit config.sys
CONFIG.LZH   (   )NT OS/2 subsystem info on config.sys
OS2APP.LZH   (   )info on OS/2 subsystem under NT
INFOBAR1.LZH (  1)System resource information bar