CHANGE—Change a Data String
The CHANGE primary command changes one string into another.
Syntax
- string1
- The search string you want to change. See Finding, seeking, changing, and excluding data.
- string2
- The string you want to replace string1. See Finding, seeking, changing, and excluding data.
- labela, labelb
- Labels identifying the start and end of the group of lines the
CHANGE command is to search.
For more information about using labels to identify a group of lines, see Labels and line ranges.
- NEXT
- Starts at the first position after the current cursor location and searches ahead to find the next occurrence of string1.
- ALL
- Starts at the top of the data and searches ahead to find all occurrences of string1.
- FIRST
- Starts at the top of the data and searches ahead to find the first occurrence of string1.
- LAST
- Starts at the bottom of the data and searches backward to find the last occurrence of string1.
- PREV
- Starts at the current cursor location and searches backward to find the previous occurrence of string1.
- CHARS
- Locates string1 anywhere the characters match.
- PREFIX
- Locates string1 at the beginning of a word.
- SUFFIX
- Locates string1 at the end of a word.
- WORD
- Locates string1 when it is delimited on both sides by blanks or other non-alphanumeric characters.
- X
- Scans only lines that are excluded from the display.
- NX
- Scans only lines that are not excluded from the display.
- start_col
- The first column to be included in the range of columns to be searched. When you specify only one column, the editor finds the string only if the string starts in the specified column.
- left_col
- The first column to be included in the range of columns to be searched.
- right_col
- The last column to be included in the range of columns to be searched.
- For more information about restricting the search to only a portion of each line, see Limiting the search to specified columns.
- The CHANGE command allows you to control the starting point and the direction of the search by positioning the cursor and using either the NEXT or PREV operand. For more information, see Starting point and direction of the search.
Description
You can use the CHANGE command with the FIND and EXCLUDE commands to find a search string, change it, and then exclude the line that contains the string from the panel.
To change the next occurrence of ME
to YOU
without
specifying any other qualifications:
- On the command line, type:
CHANGE ME YOU
- Press Enter. This command changes only the next occurrence of
the letters
ME
toYOU
. Since no other qualifications were specified, the lettersME
can be:- Uppercase or a mixture of uppercase and lowercase
- At the beginning of a word (prefix), the end of a word (suffix), or the entire word (word)
- In an excluded line or a non-excluded line
- Anywhere within the current boundaries
To change the next occurrence of ME
to YOU
,
but only if the letters are uppercase:
- On the command line, type:
CHANGE C'ME' YOU
- Press Enter. This type of change is called a character string
change (note the
C
that precedes the search string) because it changes the next occurrence of the lettersME
toYOU
only if the letters are found in uppercase. However, since no other qualifications were specified, the change occurs no matter where the letters are found, as outlined in the preceding list.
For more information, including other types of search strings, see Finding, seeking, changing, and excluding data.
Examples
The example shown changes the
first plus (+
) in the data set to a minus (-
). However,
the plus must occur on or between lines labeled .E and .S and it must
be the first character of a word:
CHANGE '+' '-' .E .S FIRST PREFIX
The example shown changes the last plus in the data set to a minus. However, the plus must occur on or between lines labeled .E and .S; it must be the last character of a word; and it must be found on an excluded line:
CHANGE '+' '-' .E .S LAST SUFFIX X
The example shown changes the plus that immediately precedes the cursor position to a minus. However, the cursor must not be positioned ahead of the lines labeled .E and .S. Also, the plus must occur on or between the labeled lines; it must be a standalone character (not part of any other word); it must be on a non-excluded line; and it must exist within columns 1 and 5:
CHANGE '+' '-' .E .S PREV WORD NX 1 5