MVSFORUMS.com Forum Index MVSFORUMS.com
A Community of and for MVS Professionals
 
 FAQFAQ   SearchSearch   Quick Manuals   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Search for a String Pattern Using Rexx

 
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF
View previous topic :: View next topic  
Author Message
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Fri Sep 08, 2006 8:40 pm    Post subject: Search for a String Pattern Using Rexx Reply with quote

I'm resubmitting this requirement. I have submitted this earlier to find whether this can be done using SORT. Now the requirement is slightly different but I would like to get a solution in Rexx.
I'm looking for a Rexx solution where I can search for a pattern of string in each record irrespective of the position.
I have used the following convention to describe the pattern.

X => Alphabets (A-Z)
9 => Number (0-9)
(SPACE) => Space


Code:

Pattern of String
------------------
X9X9X9
X9X(SPACE)9X9
X9X-9X9
X9X(SPACE)(SPACE)9X9 
X9X(SPACE)(SPACE)(SPACE)9X9
X9X(SPACE)(SPACE)(SPACE)(SPACE)9X9


The Rexx should produce a report after processing the files.

Code:
Match Found at <record number in the file>       <pattern>      <position>
Match Found at <record number in the file>       <pattern>      <position>
Match Found at <record number in the file>       <pattern>      <position>


For Example

Code:
Match Found  at 200       M2N6G9          300
Match Found  at 500       A2C   6Z9       10
Match Found  at 830       E2X-6T9         30

_________________
Thank You
-Ace
Back to top
View user's profile Send private message
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Sat Sep 09, 2006 10:22 am    Post subject: Reply with quote

A common way to do this in Rexx is something like this (not actual code):
Code:
 
'execio * diskr ddname (stem lines. finis'
do i=1 to lines.0
  line = lines.i
  line=translate(line,copies('X',52),'ABC..XYZabc...xyz')
  line=translate(line,copies('9',10),'0123456789')
  call look 'X9X9X9'
  call look 'X9X 9X9'
  ...
end
exit
look: procedure expose line i
    p = pos(arg(1),line)
    if p>0 then say 'Match found at 'right(i,9) substr(line,p,length(arg(1))) p
    return
Of course, in real code you would probably make it more efficient with the padding parameter for translate() and some of the usual program optimizations, and might change look to handle multiple occurances in the string.
Back to top
View user's profile Send private message Visit poster's website
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Sat Sep 09, 2006 2:27 pm    Post subject: Reply with quote

Thank you very much semigeezer,

The solutions working great. I never expected this can be done with a few lines of code like this.

I have a small addition to the requirement. I'm really new to Rexx, forgive me if it's really simple.

Instead of 9(numeric data 0-9), sometimes I will have O (Letter O). This is actually a data error, instead of Zero(0) they entered letter O.
Could you please tell me how can I handle this situation too.
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Sat Sep 09, 2006 2:36 pm    Post subject: Reply with quote

Also while displaying the report, instead of showing the pattern, is it possible to show the actual data.

Current Report
Code:
Match found at         1 X9X9X9  1   
Match found at         3 X9X 9X9 11


Desired report
Code:
Match found at         1 A1B1C1  1   
Match found at         3 A5B 5C5 11

_________________
Thank You
-Ace
Back to top
View user's profile Send private message
semigeezer
Supermod


Joined: 03 Jan 2003
Posts: 1014
Topics: 13
Location: Atlantis

PostPosted: Sat Sep 09, 2006 3:44 pm    Post subject: Reply with quote

I'd have to think about the first one a bit, but the 2nd is pretty easy. In my example it would just be using a separate variable for the translated line and passing both the translated line and the original one into the 'look' routine, then printing from the original one instead.

For the 1st requirement (typos), This is much harder. This would be easy using the regular expressions I mentioned in the other post because with regular expressions you can specify multiple characters for a single position to match, but in Rexx you might have to use multiple patterns. You may have to actually do the character comparisons yourself character by character.

(just a side note, Object Rexx, not part of MVS, but available on other platforms like Windows and Unix, has evaluation of regular expressions built in)
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> TSO and ISPF All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


MVSFORUMS
Powered by phpBB © 2001, 2005 phpBB Group