Tuesday, March 3, 2015

ISPF "find" command: The Basics

Introduction

The find command is used to search the next occurrence of a string or pattern from current cursor position. This command is executed as find 'text' and the "find" can be abbreviated as f "text". This command works on various panels in ISPF; member list panel where we can search member name, 3.4 where we can search dataset names and on edit / view / browse datasets. This topic mainly covers the later part.

Command Usage

The basic usage is find 'text' where the cursor will move to the next occurrence of 'text'. This basic usage can be enhanced to do advanced search by additional options. Here are the additional options and examples

Restrict search to specific rows

Suppose you have marked line 10 with label .a and line 30 with label .b and you want to look for a string between these lines. Here is how to do the same.


    find 'text' between lines marked by .a and .b
    find 'text' .a .b   

    find 'text' between line 1 and line with label .a 
    find 'text' .zf .a  

    find 'text' between label .a is and the last line. 
    find 'text' .a .zl

    Note: labels .zf, .zl and .zcsr refers 
       to first, last and current line.
    

Restrict search to specific columns

In order to search for a string between column position 10 50, we can do the following


    find 'text' between column 10 and 50.
    find 'text' 10 50   

    find 'text' between col 10 and last col (2nd operand is omitted).
    find 'text' 10      

    if the 2nd operand larger than LRECL, its is used instead.
    find 'text' 10 1000 
    

Search Directions

We can use next, prev, first, last and all along with find to find the next, previous, last and first occurrence and all occurrences respectively.


    Cursor goes to last occurrence of 'text'.
    find 'text' last    

    Cursor goes to previous occurrence from current cursor position.
    find 'text' prev    
    

Restrict string match by occurrence as prefix, suffix or standalone word. Suppose we have the following words in the dataset: text, context and texting.


    Find all 3 words. 
    find 'text' chars or
    find 'text'                  

    Find only "texting" not the other two. 
    find 'text' prefix 

    Match to "context" alone. 
    find 'text' suffix     

    Match to "text" as a whole word. 
    find 'text' word
    
Note: prefix and suffix can be abbreviated to pre and suf

Recursive find

After first match, next occurrence can be found by using the PF5 key and when the last occurrence is reached, the command wraps and goes to the first occurrence of the search string.

Repeating last search

find *
will use the lastly used search string and find the next occurrence. If * needs to be found literally then wrap * between single or double quotes.

Case in-sensitive search

find t'text'
will find text TEXT teXT etc...

Case sensitive search

find c'text'
will find text alone, not TEXT or Text...


Note:In another post, I will write about using patterns instead of literal texts as search criteria in the find command.


No comments:

Post a Comment