View previous topic :: View next topic
|
Author |
Message |
Melvyn Jacobs
New User
Joined: 05 Nov 2010 Posts: 7 Location: Australia
|
|
|
|
Hi
I'd like to search a file (will have lots of them) for a specified string, & if found then copy that record plus the next 6 to a different file.
I'm not sure if SORT can do that, any help is appreciated, thanks
MJ |
|
Back to top |
|
|
kranthikumarb
Active User
Joined: 02 Jan 2009 Posts: 115 Location: Hyderabad
|
|
|
|
Here you go!
Code: |
//STEP1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
ABC111
EDF21
31
TEXT22
32
42
52
13
23
33
/*
//OUT1 DD ...
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,4,CH,EQ,C'TEXT'),
PUSH=(10:ID=5))
OUTFIL FNAMES=OUT1,
BUILD=(1,80),INCLUDE=(10,5,CH,EQ,C'00001'),ACCEPT=6
/*
|
Just change the ID length based on your total number of records. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
It's not clear if the searched-for text can occur more than once in the data.
You don't need an ID (unless you need an ID, if they only want the first group, for instance), just PUSH a known non-blank one-byte field (like the first of the value which indicates the group) then OMIT= for blanks there. |
|
Back to top |
|
|
kranthikumarb
Active User
Joined: 02 Jan 2009 Posts: 115 Location: Hyderabad
|
|
|
|
You are correct bill. Since I have no clue of how the input looks like; which position to take, I used ID. Also, I assumed that the text to be found will always be in a specific position. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
The GROUP is the important part, and what is missing is RECORDS=6. That will give you groups of six whether one or more key is present. SS as a field-type can find the key within a given range (start, length) on the record.
If there is no byte that can be guaranteed non-blank, can use an ID or SEQ of length one (since the value doesn't matter). |
|
Back to top |
|
|
Melvyn Jacobs
New User
Joined: 05 Nov 2010 Posts: 7 Location: Australia
|
|
|
|
sorry, to be clearer, the files being searched contain JCL, I'm only searching for 1 string (on an EXEC statement), and there may be multiple instances of that in any 1 file, not necessarily in the same position |
|
Back to top |
|
|
kranthikumarb
Active User
Joined: 02 Jan 2009 Posts: 115 Location: Hyderabad
|
|
|
|
As Bill suggested, you should've tried with SS.
Code: |
//STEP1 EXEC PGM=SORT
//SYSOUT DD SYSOUT=*
//SORTIN DD *
UNWANTED
UNWANTED
UNWANTED
UNWANTED
UNWANTED
123 345 TEXT 22
WANTED
WANTED
WANTED
WANTED
WANTED
UNWANTED
UNWANTED
UNWANTED
213 3213 5654654TEXT 546456 565464
WANTED
WANTED
WANTED
WANTED
WANTED
UNWANTED
UNWANTED
UNWANTED
/*
//OUT1 DD SYSOUT=*
//SYSIN DD *
SORT FIELDS=COPY
INREC IFTHEN=(WHEN=GROUP,BEGIN=(1,80,SS,EQ,C'TEXT'),RECORDS=6,
PUSH=(81:SEQ=5))
OUTFIL FNAMES=OUT1,
BUILD=(1,80),INCLUDE=(10,5,CH,GE,C'00001')
/*
|
This will work for multiple intances of text with in one dataset. |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
Melvyn Jacobs,
It is really good to give all the information upfront.
kranthikumarb has now twice spent time on this for you, yet there is a better way.
Since to be a genuine EXEC in JCL it must be the second "word" on a line (after // or //text) then PARSE is a better way to do it. |
|
Back to top |
|
|
Melvyn Jacobs
New User
Joined: 05 Nov 2010 Posts: 7 Location: Australia
|
|
|
|
Hi Bill
Sorry about that, guess I was thinking in "general solution" terms when I asked - i.e. this time it's with JCL but next time it may not be . . .
Thanks to everyone who helped, all appreciated
cheers |
|
Back to top |
|
|
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
There's some discussion and examples here that may be helpful. |
|
Back to top |
|
|
|