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.

No comments:

Post a Comment