Tools: MPW
Advanced Search
Apple Developer Connection
Member Login Log In | Not a Member? Support

MPW Command Reference


Search

Tool

SYNTAX

Search pattern [file1] [file2]… [-b] [-e pattern]
[-exclude filename | dirname] [-f file] [-fb] [-i | -s] [-nf] [-ns]
[-p | -pv] [-q] [-r] [-rd] [-sf] [-skipalias] [-t type] [-w] [-word]

DESCRIPTION

The Search tool searches input files for lines that contain a pattern and writes those lines to standard output. For quick location of the desired text, Search adds the appropriate File and Line commands to the beginning of each line of output, as in this example:

File "LessTravelled.c"; Line 14 #made all the difference

If you execute this line, the MPW Shell opens the file and selects the line that matches the pattern. This works because File and Line are defined as MPW Shell commands: File, which is defined in the Startup file as an alias for Target, opens the file as the target window, and Line selects the line that matches the pattern.

In addition to selecting lines of text, Search can select a particular string. To perform this kind of search, you must specify a constant string for pattern instead of a selection expression. If the {SearchType} environment variable is set to 1 (meaning that "Entire Word" is selected in the Shell's Find dialog), Search will search for whole words only, in the same way that it would in response to the -word option.

INPUT

Standard input, unless you specify input files on the command line.

OUTPUT

Standard output. If you specify a selection expression for pattern, Search writes input lines that match the pattern in the following form:

File "file"; Line n # displays the matching line

If you specify a constant string for pattern, Search writes the text strings that match the pattern in the following form:

File "file"; Line regular expression # displays the line

STATUS

Search can return the following status codes:

0

no error

1

syntax error

2

pattern not found

PARAMETERS

pattern

Specifies the pattern by selection expression or by constant string. If you specify a selection expression, the line or lines containing the pattern are selected. Note that selection expressions include regular expressions and certain MPW-specific symbols and must be enclosed in slashes (/…/).

If you specify a constant string, Search selects only that text, not the lines containing the pattern. A constant string can be any literal string that you want to find. Note that you must place quotation marks around the string if it contains any spaces or special characters. When searching for a constant string, the value of the {SearchType} environment variable is used to determine if Search should search for whole words only.

file1 [file2]…

Specifies one or more input files.

OPTIONS

-b

Breaks the output text into two lines, placing the File and Line commands on the first and the matching lines of text on the second.

-e pattern

Specifies the pattern by selection expression or by constant string. This option allows the pattern to be specified after other options.

-exclude filename | dirname

Skips the specified file (or directory if -rd is specified). Among other problems, this feature prevents the undesirable behavior of searching a file (e.g., the worksheet) that is receiving the output of the search.

-f file

Writes to this file any lines not written to standard output. Normally this includes all nonmatching lines.

-fb

Flushes the output buffer after every match.

-i

Specifies a search that is not case sensitive, overriding the {CaseSensitive} variable.

-nf

Writes an error message to standard output if the pattern is not found.

-ns

Returns a status code of 0 if the pattern is not found.

-p

Writes progress information to diagnostic output.

-pv

Adds to the -p progress information every directory and file searched, whether or not a "hit" was made.

-q

Does not add the File and Line commands to matching lines. In this case, Search writes only the matching lines to standard output.

-r

Writes to standard output all lines that do not match the pattern.

-rd

Recursive search. Treats a directory as the root of a tree of files to be searched, along with any other files (or directories) specified.

-s

Specifies a case-sensitive search, overriding the {CaseSensitive} variable.

-sf

Stops searching after the first successful match. Normally Search finds all matches.

-skipalias

Specifies that aliases should be skipped. This option eliminates potential multiple hits in the same file. More importantly, it prevents the problem of an infinite loop which will eventually hang the system, a problem that is sometimes encountered with the -rd option when multiple aliases resolve to each other's directories (e.g., alias "A1" in directory "D1" resolves to "D2", which contains an alias "A2" that resolves to directory "D1").

-t type

Specifies that only files with the specified file type should be searched.

-w

Suppresses warning messages.

-word

Searches for whole words only. A whole word is defined to be any combination of characters specified in the {WordSet} environment variable. Any character in the searched file NOT in the {WordSet} environment variable will act as a word separator. This is analagous to selecting the "Entire Word" button in the Find/Replace dialog.

Note
This option is ignored for regular expression searches. •

EXAMPLES

The following command line searches the file Sample.p for the pattern /procedure/ and writes all matching lines to standard output. Note that since the first character of the pattern is a slash (/), Search automatically interprets it as a selection expression.

Search /procedure/ Sample.p

The next command line searches the same file for the string "procedure" and writes all matches for that string to standard output. Note that since "procedure" is not enclosed in slashes, Search interprets it as a constant string.

Search "procedure" Sample.p

By searching for the lines that contain Export, the example below lists all of the Export commands in the StartUp and UserStartup files:

Search /Export/ "{MPW}"StartUp "{MPW}"UserStartUp

Given the file Test1 as input, the following example writes all lines containing the string "pattern" to standard output and all other lines (that is, those not containing the string) to Test1.nonmatch.

Search /pattern/ Test1 -f Test1.nonmatch

The opposite of the preceding example, the following command writes all lines that do not contain the string "pattern " to standard output, and all other lines (that is, those containing the string) to Test2.match.

Search /pattern/ Test2 -r -f Test2.match

SEE ALSO

Find

 
 


Last Updated July 2000