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

MPW Command Reference


Replace

Built-in

SYNTAX

Replace selectionExpression replacementString [window] [-c count]

DESCRIPTION

The Replace command replaces the selection in window with the specified replacement string. To replace more than one instance of the selection, you can use -c.

INPUT

None

OUTPUT

None

ALIAS RESOLUTION

This command resolves Finder aliases that are part of a partial or complete pathname substituted for the window name. The resolved pathname must specify the name of an open window. Note that using a shell variable to designate a window is usually faster than requiring MPW to resolve a Finder alias.

STATUS

Replace can return the following status codes:

0

at least one instance of the selection found

1

syntax error

2

execution error

PARAMETERS

selectionExpression

Specifies by a selection expression the text to be replaced. The value of the MPW Shell variable {CaseSensitive} determines whether character matching is case sensitive or not.

replacementString

Specifies a replacement string. This string can contain the ® operator, allowing you to refer to parts of the selection in the replacement string. The expression ®n, where n is a digit, is replaced with the string of characters that matches the regular expression tagged by ®n in selectionExpression. Note that you should not place braces around ®n in the replacement string.

window

Specifies the window in which the selection can be found. If you do not specify a window, Replace looks for the selection in the target window. Note that it is an error to specify a window that does not exist.

OPTIONS

-c count

Repeats replacement up to count times--meaning that Replace finds count instances of the selection and replaces each with the replacement string. As a convenience, you use the character, (Option-5), to specify infinite count to replace all instances of the selection.

EXAMPLES

The following command replaces every instance of myVar in the Prog.c window with the string "myVariable":

Replace -c ∞ /myVar/ 'myVariable' Prog.c

The following command strips all spaces and tabs found at the beginning of the next five lines that start with spaces or tabs, and replaces them with the null string. Since no window is specified, the replacement is performed in the target window.

Replace -c 5 /•[ ∂t]+/ ''

The Set commands in the following example define two variables for use in the subsequent Replace command. Using the tagging operator with the {HexNum} variable, Replace converts a file containing two columns of hex digits (such as the icon list from ResEdit) into a single column of hex digits.

Set HexNum "[0-9A-F]+"
Set Spaces "[ ∂t]+"
Replace -c ∞ /({HexNum})®1{Spaces}({HexNum})®2/ ®1∂n®2

Note
The Replace command line in the last example does not set the MPW Shell variables {®1} or {®2}. When evaluating an expression that contains the tagging operator ®, the MPW Shell creates variables of the form n} that contain the matched substrings for each ® operator. However, when the tagging operator is used in editing commands instead of in expressions, the strings are not stored as MPW Shell variables. See the Evaluate command for more information on expressions. •

SEE ALSO

Clear

Find

 
 


Last Updated July 2000