[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]
Commands Reference, Volume 4

rpl Command

Purpose

Replaces all occurrences of a string in a file.

Syntax

rpl Expression Substitute

Description

The rpl command reads standard input, replaces all occurrences of the first parameter, Expression, with the second parameter, Substitute, and then writes the result to standard output.

You can use the rpl command as a filter with the Do function (the Alt-X key sequence), which runs the filter, or as a filter command from the system prompt. For information about keyboard layouts, press the F1 key (the Help function) within the INed editor. If you enter the rpl command from the system prompt, the command reads text from standard input and writes it to standard output.

If you enter the rpl command with a file name from the system prompt, it reads the text from that file, replaces all text, and writes the result to standard output.

The first value is usually a simple text string. You can also use characters (called pattern-matching characters) to form patterns that match classes of text strings. The characters that have special meanings in forming patterns are:

^ At the beginning of a pattern, a ^ (circumflex) matches the empty string at the beginning of a line.
. A . (period) matches any character except a new-line character.
$ A $ (dollar sign) matches the end of a line.
\Number Matches the character whose ASCII code is given by the Number variable, whose value can be up to three octal digits, except the octal digits 012 (new-line character). Because the rpl command works on only one line at a time, it is impossible to match a new-line character.
[ ] Matches any character in the string of characters enclosed in [ ] (brackets), but no others. If the first character of the string is a ^ (circumflex), the pattern matches any character except the new-line character and the characters in the string.
- Matches any character in a range. Within brackets, the - (minus) specifies a range. For example, [a-d] is equivalent to [abcd]. The - (minus) stands for itself if you use it as the first or last character. For example, this pattern  [ ] - ] matches the characters ] and -.
* A pattern followed by an * (asterisk) means zero or more times.
+ A pattern followed by a + (plus) means one or more times. For example, [0-9]+ is equivalent to [0-9][0-9]*.
{Minimum,Maximum} Integer values enclosed in { } (braces) indicate the number of times the preceding regular expression is applied. The Minimum number is followed by the Maximum number, which must be less than 256. Specifying only the minimum number {Minimum}, gives the exact number of times the regular expression is applied. Specifying {Minimum,} is the same as {Minimum,Infinity}. The + (plus) and * (asterisk) are equivalent to {1,} and {0,}, respectively.
( ... ) Parentheses are used for grouping. An operator (for example, *, +, { }) can work on a single character or a regular expression enclosed in parentheses; for example, (a*(cb+)*)$.

All of the preceding characters are special. If you want to use them as themselves, you must precede each with a \ (reverse slash). Also, to avoid conflicts with AIX special characters, enclose the Expression and Substitute parameters in single quotation marks when they contain any special characters.

To delete a string using the rpl command, use the null string "" (two double quotation marks) as the replacement string.

If lines are longer than 256 characters, if you do not give two values, or if the first value is the null string, the rpl command exits with the value -2.

Examples

See the following for examples of replacing character strings.

Note: If you are using a locale other than En_US, the following examples may not include all alphabetic characters.
  1. To replace a legal FORTRAN identifier (an alphabetic character followed by as many as five alphanumeric characters) with xxx, enter:
    rpl '[A-Za-z][A-Za-z0-9]{0,5}' xxx
  2. To replace all occurrences of the character string sky with blue sky in the skyfile file and put the result in the bluefile file, enter:
    rpl sky "blue sky" <skyfile >bluefile

Related Information

The e command.

Editor Overview in AIX Version 4.3 INed Editor User's Guide introduces general concepts about the INed editor.

Running AIX and Filter Commands with the INed Editor in AIX Version 4.3 INed Editor User's Guide.


[ Next Article | Previous Article | Book Contents | Library Home | Legal | Search ]