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 

Pattern Matching

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


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Fri Aug 18, 2006 4:25 pm    Post subject: Pattern Matching Reply with quote

I have a FB file with length 9000. I want to check for some string patterns in this file (at position 2029 and length 40) and replace it with some other value. The pattern can appear at any position between 2029 and 2029+40. Is it possible to search for the pattern and replace using SORT. I have used the following convention to describe the pattern.

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


First Pattern

Code:

Input
-----
X9X9X9
X9X(SPACE)9X9
X9X-9X9
X9X(SPACE)(SPACE)9X9 
X9X(SPACE)(SPACE)(SPACE)9X9
X9X(SPACE)(SPACE)(SPACE)(SPACE)9X9

Output
------
X9X0Z0
X9X(SPACE)0Z0
X9X-0Z0
X9X(SPACE)(SPACE)0Z0 
X9X(SPACE)(SPACE)(SPACE)0Z0
X9X(SPACE)(SPACE)(SPACE)(SPACE)0z0


Second Pattern
Code:

Input
-----
99999-9999
99999(SPACE)(SPACE)9999
99999(SPACE)(SPACE)(SPACE)9999
99999(SPACE)(SPACE)(SPACE)(SPACE)9999
99999

Output
------
99000-0000
99000(SPACE)(SPACE)0000
99000(SPACE)(SPACE)(SPACE)0000
99999(SPACE)(SPACE)(SPACE)(SPACE)0000
99000

_________________
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 Aug 19, 2006 9:37 am    Post subject: Pattern Matching Reply with quote

There is a correction in the Second Pattern.

Second Pattern
Code:

Input
-----
99999-9999
99999(SPACE)(SPACE)9999
99999(SPACE)(SPACE)(SPACE)9999
99999(SPACE)(SPACE)(SPACE)(SPACE)9999
99999

Output
------
99000-0000
99000(SPACE)(SPACE)0000
99000(SPACE)(SPACE)(SPACE)0000
99000(SPACE)(SPACE)(SPACE)(SPACE)0000   ===> corrected
99000


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


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Sat Aug 19, 2006 3:39 pm    Post subject: Reply with quote

ace,

I could not get the solution using SORT but i have got the results by coding a COBOL Program and my assumption was that the Input patterns could come anywhere between columns 1 - 80.If you desire i can post the solution but experts have to correct me if the solution is correct / not .
_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Sat Aug 19, 2006 6:25 pm    Post subject: Reply with quote

Thanks Shekar.
I do have a COBOL program for this requirement. But just thought whether it's feasible using SORT.
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
shekar123
Advanced


Joined: 22 Jul 2005
Posts: 528
Topics: 90
Location: Bangalore India

PostPosted: Sun Aug 20, 2006 8:16 am    Post subject: Reply with quote

Ace,

I have tried using SORT with the assumption that data always starts from COL 1 but really do not know whether the solution is correct / not.Experts need to correct me for this.

Try this code:
Code:

//STEP010  EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SORTIN   DD *
A1B2C3
A1B(SPACE)2C3
A1B-2C3
A1B(SPACE)(SPACE)2C3
A1B(SPACE)(SPACE)(SPACE)2C3
A1B(SPACE)(SPACE)(SPACE)(SPACE)2C3
//SORTOUT  DD SYSOUT=*
//SYSOUT   DD SYSOUT=*
//SYSPRINT DD SYSOUT=*
//SYSIN    DD *
 OPTION COPY
 OUTREC IFTHEN=(WHEN=(4,28,CH,EQ,C'(SPACE)(SPACE)(SPACE)(SPACE)',AND,
               32,1,BI,EQ,1,OR,
               32,1,BI,EQ,2,OR,
               32,1,BI,EQ,3,OR,
               32,1,BI,EQ,4,OR,
               32,1,BI,EQ,5,OR,
               32,1,BI,EQ,6,OR,
               32,1,BI,EQ,7,OR,
               32,1,BI,EQ,8,OR,
               32,1,BI,EQ,9,OR,
               32,1,BI,EQ,0,OR,
               33,1,CH,EQ,C'A',OR,
               33,1,CH,EQ,C'B',OR,
               33,1,CH,EQ,C'C',OR,
               33,1,CH,EQ,C'D',OR,
               33,1,CH,EQ,C'E',OR,
               33,1,CH,EQ,C'F',OR,
               33,1,CH,EQ,C'G',OR,
               33,1,CH,EQ,C'H',OR,
               33,1,CH,EQ,C'I',OR,
               33,1,CH,EQ,C'J',OR,
               33,1,CH,EQ,C'K',OR,
               33,1,CH,EQ,C'L',OR,
               33,1,CH,EQ,C'M',OR,
               33,1,CH,EQ,C'N',OR,
               33,1,CH,EQ,C'O',OR,
               33,1,CH,EQ,C'P',OR,
               33,1,CH,EQ,C'Q',OR,
               33,1,CH,EQ,C'R',OR,
               33,1,CH,EQ,C'S',OR,
               33,1,CH,EQ,C'T',OR,
               33,1,CH,EQ,C'U',OR,
               33,1,CH,EQ,C'V',OR,
               33,1,CH,EQ,C'W',OR,
               33,1,CH,EQ,C'X',OR,
               33,1,CH,EQ,C'Y',OR,
               33,1,CH,EQ,C'Z',OR,
               34,1,BI,EQ,1,OR,
               34,1,BI,EQ,2,OR,
               34,1,BI,EQ,3,OR,
               34,1,BI,EQ,4,OR,
               34,1,BI,EQ,5,OR,
               34,1,BI,EQ,6,OR,
               34,1,BI,EQ,7,OR,
               34,1,BI,EQ,8,OR,
               34,1,BI,EQ,9,OR,
               34,1,BI,EQ,0),
        OVERLAY=(1:1,3,4:4,14,C'(SPACE)(SPACE)(SPACE)(SPACE)',
                32:C'0',33:C'Z',34:C'0',35:C'             ')),
        IFTHEN=(WHEN=(4,21,CH,EQ,C'(SPACE)(SPACE)(SPACE)',AND,
               25,1,BI,EQ,1,OR,
               25,1,BI,EQ,2,OR,
               25,1,BI,EQ,3,OR,
               25,1,BI,EQ,4,OR,
               25,1,BI,EQ,5,OR,
               25,1,BI,EQ,6,OR,
               25,1,BI,EQ,7,OR,
               25,1,BI,EQ,8,OR,
               25,1,BI,EQ,9,OR,
               25,1,BI,EQ,0,OR,
               26,1,CH,EQ,C'A',OR,
               26,1,CH,EQ,C'B',OR,
               26,1,CH,EQ,C'C',OR,
               26,1,CH,EQ,C'D',OR,
               26,1,CH,EQ,C'E',OR,
               26,1,CH,EQ,C'F',OR,
               26,1,CH,EQ,C'G',OR,
               26,1,CH,EQ,C'H',OR,
               26,1,CH,EQ,C'I',OR,
               26,1,CH,EQ,C'J',OR,
               26,1,CH,EQ,C'K',OR,
               26,1,CH,EQ,C'L',OR,
               26,1,CH,EQ,C'M',OR,
               26,1,CH,EQ,C'N',OR,
               26,1,CH,EQ,C'O',OR,
               26,1,CH,EQ,C'P',OR,
               26,1,CH,EQ,C'Q',OR,
               26,1,CH,EQ,C'R',OR,
               26,1,CH,EQ,C'S',OR,
               26,1,CH,EQ,C'T',OR,
               26,1,CH,EQ,C'U',OR,
               26,1,CH,EQ,C'V',OR,
               26,1,CH,EQ,C'W',OR,
               26,1,CH,EQ,C'X',OR,
               26,1,CH,EQ,C'Y',OR,
               26,1,CH,EQ,C'Z',OR,
               27,1,BI,EQ,1,OR,
               27,1,BI,EQ,2,OR,
               27,1,BI,EQ,3,OR,
               27,1,BI,EQ,4,OR,
               27,1,BI,EQ,5,OR,
               27,1,BI,EQ,6,OR,
               27,1,BI,EQ,7,OR,
               27,1,BI,EQ,8,OR,
               27,1,BI,EQ,9,OR,
               27,1,BI,EQ,0),
        OVERLAY=(1:1,3,4:4,21,C'(SPACE)(SPACE)(SPACE)',
                25:C'0',26:C'Z',27:C'0',28:C'                    ')),
        IFTHEN=(WHEN=(4,14,CH,EQ,C'(SPACE)(SPACE)',AND,
               18,1,BI,EQ,1,OR,
               18,1,BI,EQ,2,OR,
               18,1,BI,EQ,3,OR,
               18,1,BI,EQ,4,OR,
               18,1,BI,EQ,5,OR,
               18,1,BI,EQ,6,OR,
               18,1,BI,EQ,7,OR,
               18,1,BI,EQ,8,OR,
               18,1,BI,EQ,9,OR,
               18,1,BI,EQ,0,OR,
               19,1,CH,EQ,C'A',OR,
               19,1,CH,EQ,C'B',OR,
               19,1,CH,EQ,C'C',OR,
               19,1,CH,EQ,C'D',OR,
               19,1,CH,EQ,C'E',OR,
               19,1,CH,EQ,C'F',OR,
               19,1,CH,EQ,C'G',OR,
               19,1,CH,EQ,C'H',OR,
               19,1,CH,EQ,C'I',OR,
               19,1,CH,EQ,C'J',OR,
               19,1,CH,EQ,C'K',OR,
               19,1,CH,EQ,C'L',OR,
               19,1,CH,EQ,C'M',OR,
               19,1,CH,EQ,C'N',OR,
               19,1,CH,EQ,C'O',OR,
               19,1,CH,EQ,C'P',OR,
               19,1,CH,EQ,C'Q',OR,
               19,1,CH,EQ,C'R',OR,
               19,1,CH,EQ,C'S',OR,
               19,1,CH,EQ,C'T',OR,
               19,1,CH,EQ,C'U',OR,
               19,1,CH,EQ,C'V',OR,
               19,1,CH,EQ,C'W',OR,
               19,1,CH,EQ,C'X',OR,
               19,1,CH,EQ,C'Y',OR,
               19,1,CH,EQ,C'Z',OR,
               20,1,BI,EQ,1,OR,
               20,1,BI,EQ,2,OR,
               20,1,BI,EQ,3,OR,
               20,1,BI,EQ,4,OR,
               20,1,BI,EQ,5,OR,
               20,1,BI,EQ,6,OR,
               20,1,BI,EQ,7,OR,
               20,1,BI,EQ,8,OR,
               20,1,BI,EQ,9,OR,
               20,1,BI,EQ,0),
        OVERLAY=(1:1,3,4:4,14,C'(SPACE)(SPACE)',18:C'0',19:C'Z',
                20:C'0',21:C'                               ')),
        IFTHEN=(WHEN=(4,7,CH,EQ,C'(SPACE)',AND,
               11,1,BI,EQ,1,OR,
               11,1,BI,EQ,2,OR,
               11,1,BI,EQ,3,OR,
               11,1,BI,EQ,4,OR,
               11,1,BI,EQ,5,OR,
               11,1,BI,EQ,6,OR,
               11,1,BI,EQ,7,OR,
               11,1,BI,EQ,8,OR,
               11,1,BI,EQ,9,OR,
               11,1,BI,EQ,0,OR,
               12,1,CH,EQ,C'A',OR,
               12,1,CH,EQ,C'B',OR,
               12,1,CH,EQ,C'C',OR,
               12,1,CH,EQ,C'D',OR,
               12,1,CH,EQ,C'E',OR,
               12,1,CH,EQ,C'F',OR,
               12,1,CH,EQ,C'G',OR,
               12,1,CH,EQ,C'H',OR,
               12,1,CH,EQ,C'I',OR,
               12,1,CH,EQ,C'J',OR,
               12,1,CH,EQ,C'K',OR,
               12,1,CH,EQ,C'L',OR,
               12,1,CH,EQ,C'M',OR,
               12,1,CH,EQ,C'N',OR,
               12,1,CH,EQ,C'O',OR,
               12,1,CH,EQ,C'P',OR,
               12,1,CH,EQ,C'Q',OR,
               12,1,CH,EQ,C'R',OR,
               12,1,CH,EQ,C'S',OR,
               12,1,CH,EQ,C'T',OR,
               12,1,CH,EQ,C'U',OR,
               12,1,CH,EQ,C'V',OR,
               12,1,CH,EQ,C'W',OR,
               12,1,CH,EQ,C'X',OR,
               12,1,CH,EQ,C'Y',OR,
               12,1,CH,EQ,C'Z',OR,
               13,1,BI,EQ,1,OR,
               13,1,BI,EQ,2,OR,
               13,1,BI,EQ,3,OR,
               13,1,BI,EQ,4,OR,
               13,1,BI,EQ,5,OR,
               13,1,BI,EQ,6,OR,
               13,1,BI,EQ,7,OR,
               13,1,BI,EQ,8,OR,
               13,1,BI,EQ,9,OR,
               13,1,BI,EQ,0),
        OVERLAY=(1:1,3,4:4,7,C'(SPACE)',11:C'0',12:C'Z',
                13:C'0',14:C'    ')),
        IFTHEN=(WHEN=(4,1,CH,EQ,C'-',AND,
               5,1,BI,EQ,1,OR,
               5,1,BI,EQ,2,OR,
               5,1,BI,EQ,3,OR,
               5,1,BI,EQ,4,OR,
               5,1,BI,EQ,5,OR,
               5,1,BI,EQ,6,OR,
               5,1,BI,EQ,7,OR,
               5,1,BI,EQ,8,OR,
               5,1,BI,EQ,9,OR,
               5,1,BI,EQ,0,OR,
               6,1,CH,EQ,C'A',OR,
               6,1,CH,EQ,C'B',OR,
               6,1,CH,EQ,C'C',OR,
               6,1,CH,EQ,C'D',OR,
               6,1,CH,EQ,C'E',OR,
               6,1,CH,EQ,C'F',OR,
               6,1,CH,EQ,C'G',OR,
               6,1,CH,EQ,C'H',OR,
               6,1,CH,EQ,C'I',OR,
               6,1,CH,EQ,C'J',OR,
               6,1,CH,EQ,C'K',OR,
               6,1,CH,EQ,C'L',OR,
               6,1,CH,EQ,C'M',OR,
               6,1,CH,EQ,C'N',OR,
               6,1,CH,EQ,C'O',OR,
               6,1,CH,EQ,C'P',OR,
               6,1,CH,EQ,C'Q',OR,
               6,1,CH,EQ,C'R',OR,
               6,1,CH,EQ,C'S',OR,
               6,1,CH,EQ,C'T',OR,
               6,1,CH,EQ,C'U',OR,
               6,1,CH,EQ,C'V',OR,
               6,1,CH,EQ,C'W',OR,
               6,1,CH,EQ,C'X',OR,
               6,1,CH,EQ,C'Y',OR,
               6,1,CH,EQ,C'Z',OR,
               7,1,BI,EQ,1,OR,
               7,1,BI,EQ,2,OR,
               7,1,BI,EQ,3,OR,
               7,1,BI,EQ,4,OR,
               7,1,BI,EQ,5,OR,
               7,1,BI,EQ,6,OR,
               7,1,BI,EQ,7,OR,
               7,1,BI,EQ,8,OR,
               7,1,BI,EQ,9,OR,
               7,1,BI,EQ,0),
        OVERLAY=(4:C'-',5:C'0',6:C'Z',7:C'0')),
        IFTHEN=(WHEN=(4,1,BI,EQ,1,OR,
               4,1,BI,EQ,2,OR,
               4,1,BI,EQ,3,OR,
               4,1,BI,EQ,4,OR,
               4,1,BI,EQ,5,OR,
               4,1,BI,EQ,6,OR,
               4,1,BI,EQ,7,OR,
               4,1,BI,EQ,8,OR,
               4,1,BI,EQ,9,OR,
               4,1,BI,EQ,0,OR,
               5,1,CH,EQ,C'A',OR,
               5,1,CH,EQ,C'B',OR,
               5,1,CH,EQ,C'C',OR,
               5,1,CH,EQ,C'D',OR,
               5,1,CH,EQ,C'E',OR,
               5,1,CH,EQ,C'F',OR,
               5,1,CH,EQ,C'G',OR,
               5,1,CH,EQ,C'H',OR,
               5,1,CH,EQ,C'I',OR,
               5,1,CH,EQ,C'J',OR,
               5,1,CH,EQ,C'K',OR,
               5,1,CH,EQ,C'L',OR,
               5,1,CH,EQ,C'M',OR,
               5,1,CH,EQ,C'N',OR,
               5,1,CH,EQ,C'O',OR,
               5,1,CH,EQ,C'P',OR,
               5,1,CH,EQ,C'Q',OR,
               5,1,CH,EQ,C'R',OR,
               5,1,CH,EQ,C'S',OR,
               5,1,CH,EQ,C'T',OR,
               5,1,CH,EQ,C'U',OR,
               5,1,CH,EQ,C'V',OR,
               5,1,CH,EQ,C'W',OR,
               5,1,CH,EQ,C'X',OR,
               5,1,CH,EQ,C'Y',OR,
               5,1,CH,EQ,C'Z',OR,
               6,1,BI,EQ,1,OR,
               6,1,BI,EQ,2,OR,
               6,1,BI,EQ,3,OR,
               6,1,BI,EQ,4,OR,
               6,1,BI,EQ,5,OR,
               6,1,BI,EQ,6,OR,
               6,1,BI,EQ,7,OR,
               6,1,BI,EQ,8,OR,
               6,1,BI,EQ,9,OR,
               6,1,BI,EQ,0),
        OVERLAY=(4:C'0',5:C'Z',6:C'0'))
/*
//

OUTPUT
Code:

A1B0Z0                                                                         
A1B(SPACE)0Z0                                                                   
A1B-0Z0                                                                         
A1B(SPACE)(SPACE)0Z0                                                           
A1B(SPACE)(SPACE)(SPACE)0Z0                                                     
A1B(SPACE)(SPACE)(SPACE)(SPACE)0Z0                                             

_________________
Shekar
Grow Technically
Back to top
View user's profile Send private message
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Mon Aug 21, 2006 5:56 pm    Post subject: Reply with quote

Thanks for your effort Shekar.
But my requirement is little different as mentioned in my initial post. The pattern can appear at any position between 2029 and 2029+40. So it's not occuring at a fixed position as per your solution.
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Mon Aug 21, 2006 6:33 pm    Post subject: Reply with quote

Ace,

I can't really think of any way to do what you want with built-in functions. Of course, you could write an E15 or E35 exit with the appropriate logic to do it, but that's probably not what you want to do.
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Tue Aug 22, 2006 11:08 am    Post subject: Reply with quote

Thanks Frank.
Is it possible to build the pattern using ALTSEQ and search for it using the Substring (SS) function.
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
Frank Yaeger
Sort Forum Moderator
Sort Forum Moderator


Joined: 02 Dec 2002
Posts: 1618
Topics: 31
Location: San Jose

PostPosted: Tue Aug 22, 2006 11:51 am    Post subject: Reply with quote

Quote:
Is it possible to build the pattern using ALTSEQ and search for it using the Substring (SS) function.


I don't see how.
_________________
Frank Yaeger - DFSORT Development Team (IBM)
Specialties: JOINKEYS, FINDREP, WHEN=GROUP, ICETOOL, Symbols, Migration
DFSORT is on the Web at:
www.ibm.com/storage/dfsort
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Alain Benveniste
Beginner


Joined: 04 May 2003
Posts: 92
Topics: 4
Location: Paris, France

PostPosted: Wed Aug 23, 2006 4:57 am    Post subject: Reply with quote

Ace,

From your input

Code:

X9X9X9
X9X(SPACE)9X9
X9X-9X9
X9X(SPACE)(SPACE)9X9 
X9X(SPACE)(SPACE)(SPACE)9X9
X9X(SPACE)(SPACE)(SPACE)(SPACE)9X9

do you really have blanks from 9X9 to 2029+40 ?

Alain
Back to top
View user's profile Send private message
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Wed Aug 23, 2006 12:51 pm    Post subject: Reply with quote

No Alain. It's not blank always.
I may have some other data like name, address etc. in some of the records(very rarely though).
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Fri Sep 08, 2006 11:06 am    Post subject: Reply with quote

Hi All,
I have the above requirement with some changes. The Pattern format remains same, but this time I would like to know whether this can be done using Rexx. Also the Pattern can appear in any place in a given record. Please let me know whether we can handle different file types with different LRECL in Rexx.
_________________
Thank You
-Ace
Back to top
View user's profile Send private message
ace
Beginner


Joined: 24 Feb 2004
Posts: 58
Topics: 23

PostPosted: Fri Sep 08, 2006 11:52 am    Post subject: Reply with quote

Forgot to add these ..
Basically I'm looking for a report while processing the file for the matched pattern.

Report is something Like

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
Display posts from previous:   
Post new topic   Reply to topic   printer-friendly view    MVSFORUMS.com Forum Index -> Utilities 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