FIND and CHANGE are powerful commands for locating and replacing text in the ISPF editor. FIND locates text without modifying it, while CHANGE locates and replaces text. Both commands support single operations (one occurrence at a time) and global operations (all occurrences at once), along with various qualifiers that control search direction and matching behavior. This tutorial covers single and global operations, qualifiers, and best practices for using FIND and CHANGE effectively.
Mastering FIND and CHANGE is essential for efficient editing, especially when working with large files or making systematic changes. Understanding when to use single vs. global operations and which qualifiers to apply helps you work more efficiently and avoid errors.
Understanding FIND and CHANGE
FIND and CHANGE are primary commands entered on the command line.
FIND Command
FIND:
Locates text in the file
Positions your cursor at the match
Does not modify the file
Useful for locating text before changing it
CHANGE Command
CHANGE:
Locates text in the file
Replaces it with new text
Modifies the file
Can operate on single or multiple occurrences
Basic Syntax
Basic syntax:
text
1
2
FIND searchtext
CHANGE oldtext newtext
Single Operations
Single operations work on one occurrence at a time, giving you control over each match.
Single FIND
To find a single occurrence:
Type "FIND" followed by the text to search for
Press Enter
The cursor moves to the next occurrence
Repeat to find subsequent occurrences
Single FIND Example
Finding "PROCEDURE":
text
1
Command ===> FIND PROCEDURE
This finds the next occurrence of "PROCEDURE" and positions the cursor there.
Single CHANGE
To change a single occurrence:
Type "CHANGE" followed by old text and new text
Press Enter
The first occurrence is replaced
Repeat to replace subsequent occurrences
Single CHANGE Example
Replacing "OLD" with "NEW":
text
1
Command ===> CHANGE OLD NEW
This finds the next occurrence of "OLD" and replaces it with "NEW".
Advantages of Single Operations
Single operations provide:
Control: You decide which occurrences to replace
Review: You can review each match before replacing
Safety: Less risk of unintended replacements
Flexibility: You can skip some occurrences
Global Operations
Global operations work on all occurrences at once, making bulk changes efficient.
Global FIND
Some ISPF versions support global FIND:
FIND with ALL may highlight all occurrences
Useful for seeing all matches at once
Helps verify what will be affected
Global CHANGE
To change all occurrences:
Type "CHANGE" followed by old text, new text, and "ALL"
Press Enter
All occurrences are replaced in one operation
A message shows how many replacements were made
Global CHANGE Example
Replacing all occurrences:
text
1
Command ===> CHANGE OLD NEW ALL
This replaces every occurrence of "OLD" with "NEW" throughout the entire file.
Advantages of Global Operations
Global operations provide:
Speed: Faster for bulk changes
Consistency: Ensures all occurrences are changed
Efficiency: One command instead of many
Completeness: No risk of missing occurrences
When to Use Global Operations
Use global operations when:
You're certain all occurrences should be replaced
The search text is specific and unambiguous
You've verified the search text is correct
You need to make systematic changes throughout the file
Qualifiers
Qualifiers modify how FIND and CHANGE operate, controlling search direction and matching behavior.
Direction Qualifiers
Direction qualifiers control search direction:
NEXT: Find/change the next occurrence (default, forward direction)
PREV: Find/change the previous occurrence (backward direction)
FIRST: Find/change the first occurrence in the file
LAST: Find/change the last occurrence in the file
Direction Qualifier Examples
Finding the previous occurrence:
text
1
Command ===> FIND PROCEDURE PREV
Finding the first occurrence:
text
1
Command ===> FIND PROCEDURE FIRST
Changing the last occurrence:
text
1
Command ===> CHANGE OLD NEW LAST
Scope Qualifiers
Scope qualifiers control how many occurrences are affected:
ALL: Operate on all occurrences (global operation)
NX: Operate on the next occurrence (abbreviation for NEXT)
No qualifier: Operate on the next occurrence (single operation)
Scope Qualifier Examples
Changing all occurrences:
text
1
Command ===> CHANGE OLD NEW ALL
Changing the next occurrence (explicit):
text
1
Command ===> CHANGE OLD NEW NX
Matching Qualifiers
Matching qualifiers control how text is matched:
WORD: Match whole words only (not part of a larger word)
PREFIX: Match at the start of a word
SUFFIX: Match at the end of a word
No qualifier: Match anywhere in the text (default)
Matching Qualifier Examples
Finding whole words only:
text
1
Command ===> FIND OLD WORD
This finds "OLD" only when it appears as a complete word, not as part of "BOLD" or "FOLD".
Changing with word matching:
text
1
Command ===> CHANGE OLD NEW WORD ALL
This replaces "OLD" with "NEW" only when "OLD" appears as a whole word.
Combining Qualifiers
You can combine multiple qualifiers:
text
1
Command ===> CHANGE OLD NEW WORD ALL
This combines WORD (whole word matching) with ALL (global operation).
Using Delimiters
Delimiters are used when search or replacement text contains spaces.
Why Use Delimiters?
When text contains spaces:
ISPF needs to know where the search text ends
Delimiters mark the boundaries of the text
Common delimiters: /, ', ", or other special characters
Delimiter Examples
Using forward slash delimiter:
text
1
Command ===> CHANGE /old text/new text/
Using single quote delimiter:
text
1
Command ===> CHANGE 'old text' 'new text'
Using double quote delimiter:
text
1
Command ===> CHANGE "old text" "new text"
Delimiter Rules
When using delimiters:
Use the same delimiter for both old and new text
Choose a delimiter that doesn't appear in your text
Delimiters are not part of the search or replacement text
Some ISPF versions have specific delimiter requirements
FIND Before CHANGE Workflow
Using FIND before CHANGE helps you verify what will be changed.
Recommended Workflow
The workflow:
Step 1: Use FIND to locate occurrences
Step 2: Review each match to verify it should be changed
Step 3: Use CHANGE to replace occurrences one at a time
Step 4: Or use CHANGE ALL if all occurrences should be changed
FIND Before CHANGE Example
Example workflow:
text
1
2
3
4
5
6
Command ===> FIND OLD
(Review the match)
Command ===> CHANGE OLD NEW
(Review the replacement)
Command ===> FIND OLD
(Continue to next occurrence)
Benefits of FIND Before CHANGE
This workflow provides:
Verification: See what will be changed before changing it
Control: Decide which occurrences to replace
Safety: Avoid unintended replacements
Confidence: Know your changes are correct
Best Practices
Following best practices helps you use FIND and CHANGE effectively and safely.
Verify Before ALL: Always verify your search text before using CHANGE ALL
Use FIND First: Use FIND to locate occurrences before using CHANGE
Save Before Global: Save your work before performing global operations
Use WORD When Appropriate: Use WORD qualifier to avoid partial matches
Test on Small Files: Test your search text on small files or sections first
Review Results: Review the results of global operations
Use CANCEL If Needed: Use CANCEL to undo if you make mistakes (before saving)
Combine Qualifiers Carefully: Understand how qualifiers interact when combined
Common Scenarios
Here are common scenarios for using FIND and CHANGE.
Renaming Variables
When renaming variables:
Use FIND to locate all occurrences
Use CHANGE with WORD qualifier to match whole words only
Use ALL to replace all occurrences at once
Verify the replacements are correct
Updating Text Strings
When updating text strings:
Use FIND to locate occurrences
Use CHANGE with delimiters if text contains spaces
Use single operations if some occurrences shouldn't be changed
Use global operations if all occurrences should be changed
Fixing Typos
When fixing typos:
Use FIND to locate the typo
Use CHANGE to fix it
Use ALL if the typo appears multiple times
Use WORD if the typo might be part of other words
Error Prevention
Preventing errors when using FIND and CHANGE.
Common Mistakes
Avoid these common mistakes:
Using ALL Without Verification: Always verify search text before using ALL
Missing WORD Qualifier: Use WORD when you only want whole word matches
Incorrect Delimiters: Use proper delimiters for text with spaces
Not Saving Before Global: Save before global operations so you can CANCEL if needed
Case Sensitivity: Be aware of case sensitivity in your ISPF version
Recovery Strategies
If you make mistakes:
Before Saving: Use CANCEL to discard all changes
After Saving: You may need to manually undo or restore from backup
Partial Mistakes: Use FIND and CHANGE to fix specific occurrences
Prevention: Always verify before executing global operations
Explain Like I'm 5: FIND and CHANGE
Think of FIND and CHANGE like a search and replace tool for your story:
FIND is like a magnifying glass. You tell it "find the word 'cat'!" and it shows you where all the "cat" words are in your story. It doesn't change anything, just shows you where things are, like using a magnifying glass to find hidden objects in a picture!
CHANGE is like a magic eraser and pen. You tell it "find the word 'cat' and change it to 'dog'!" and it finds "cat" and replaces it with "dog". It's like having a magic tool that finds words and changes them automatically!
Single means doing it one at a time. Like finding one "cat" and changing it to "dog", then finding the next "cat" and changing it. You do it step by step, like changing one thing at a time!
Global (ALL) means doing it all at once. Like telling the magic tool "find ALL the 'cat' words and change them ALL to 'dog' at the same time!" It changes everything in one go, like having a super-fast helper that does everything at once!
Qualifiers are like special instructions. You can say "find 'cat' but only if it's a whole word" (WORD), or "find the first 'cat'" (FIRST), or "find the last 'cat'" (LAST). They're like giving special directions to make the search smarter!
So FIND and CHANGE are like special tools that help you find words in your file and change them, either one at a time (single) or all at once (global), with special instructions (qualifiers) to make them work exactly how you want!
Practice Exercises
Complete these exercises to reinforce your understanding of FIND and CHANGE:
Exercise 1: Single FIND Operations
Practice single FIND operations: use FIND to locate different words in a test file, try FIND with PREV and FIRST qualifiers, and practice navigating through search results. Build familiarity with single search operations.
Exercise 2: Single CHANGE Operations
Practice single CHANGE operations: use CHANGE to replace occurrences one at a time, try different qualifiers, and practice using delimiters for text with spaces. Learn to control single replacements.
Exercise 3: Global CHANGE Operations
Practice global CHANGE operations: use CHANGE with ALL to replace all occurrences, verify your search text first, and observe how many replacements are made. Practice safe global operations.
Exercise 4: Qualifiers
Practice using qualifiers: try WORD, PREV, FIRST, LAST, and ALL qualifiers, combine qualifiers, and observe how they affect FIND and CHANGE behavior. Master qualifier usage.
Exercise 5: FIND Before CHANGE Workflow
Practice the FIND before CHANGE workflow: use FIND to locate occurrences, review them, then use CHANGE to replace them. Practice this workflow until it becomes natural.
Test Your Knowledge
1. What does CHANGE with ALL qualifier do?
Replaces one occurrence
Replaces all occurrences in the file
Only finds occurrences
Saves the file
2. What is the difference between single and global CHANGE?