Showing posts with label Mainframe_cmds_ISPF. Show all posts
Showing posts with label Mainframe_cmds_ISPF. Show all posts

Wednesday, March 4, 2015

ISPF "find" command: Pattern Matching

Introduction

In the previous post called ISPF find command: The Basics written on Mar 3, 2015 , I have written about basic usage find command including search direction, recursive search, case sensitive and insenstive search etc. You may find the blog here at http://mktutes.blogspot.in/2015/03/ispf-find-command-basics.html

In this post, I will discuss about using patterns called picture strings as search criteria instead of literal strings.

Pattern Matching using the Picture string

Perhaps this is the most advanced feature and the coolest one in my opinion. So far we have used literal strings as search criteria and enhanced the search by restricting by rows and columns, prefix,suffix and full words. By using picture strings, we can classify characters broadly into 9 different categories and assign a symbol to each category and use these symbols to find any char that belongs to the character group instead of specific character. For example if we want to find a date of birth that has the following pattern 'dd/mm/ccyy', we can find all the dates using picture string irrespective of the actual numbers. First lets see the 9 categories.

  • = - any character
  • @ - alphabets; both upper and lower case versions
  • # - numeric characters
  • $ - special characters such as #, @ ! etc...
  • ¬ - non-blank characters
  • . - invalid or non-printable characters (dot)
  • - - non-numeric characters (dash)
  • < - lower case alphabets
  • > - upper case alphabets

Examples using picture string

Finding dates that has the following format "mm/dd/ccyy'. The dataset contains two dates 05/25/1980 and 05/25/2014

find p'##-##-####'
will match both dates.

find p'##-##-20##'
will match only the 2nd date alone.

Finding COBOL paragraphs that were commented out (Assume the para names start at pos 8 and they have a nnnn-some-para-name format.)

find p'¬####-@@@@'
find occurrence of a non blank char at pos 7 followed by 4 numbers and four alpha chars at-least

Using Picture String in find has a lot of potential. For example, we can find US phone numbers using pattern p'###-###-####' or Indian phone numbers using p'+91-#####-#####', commented lines in a COBOL program by using find p'¬' 7 .

I am planning to write another post are two on using find and exclude commands together and using change command with picture string in the future.



“I’ve noticed that sometimes when we aren’t actively searching for something, what we seek, finds us.” -- Darryl Webb.

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.