Page 1 of 1

How to check for specific string in the file

PostPosted: Mon Aug 13, 2012 9:08 pm
by Irene Ioujanina
Hi,

May I please ask for assistance.
I have a file which could contain 1 or many records. In one of the records could be a specific 'key' string (in any record, in any position) lets say 'THIS IS A KEY'. I hope there is a way to check if it's present in the file, and create a new file with just one this record, with the 'KEY' string' .

For instance, the file has the following records:
header 11111111     text    key
4 jfjfjfjf   9 9 9 9 99
4gjgjgjgj                  900d0d0d
  8888     THIS IS a KEY
   8888 00s0s0s0s0

After the program run, it will create a file with just one record:
8888 THIS IS a KEY

If there is NO 'KEY string' in the first file - the resulting file will be created empty, or has 0(zero) records.
Hope it is possible.
Thanks so much in advance,
Irene

Re: How to check for specific string in the file

PostPosted: Mon Aug 13, 2012 9:55 pm
by dick scherrer
Hello,

Your data may or may not be "Code'd" as you want. Suggest when posting code or data or jcl etc, you use the Code tag and the Preview function so you can see your post as it will appear to the forum (rathe than how it appears in the Reply editor).

What should happen if there are more than one of the "key" is found in the file?

You should be able to do what you want using INCLUDE and specifying SS (substring) for the key. There are examples in the forum.

Re: How to check for specific string in the file

PostPosted: Tue Aug 14, 2012 2:20 am
by Irene Ioujanina
Thanks.

It is always one, like a 'TOTAL' by the end of the file. The purpose is just to identify if its present in the file at all. As soon as we found just one, it is good enought for me.
Could you please provide a link to examples you mentioned?

Thank you.

Re: How to check for specific string in the file

PostPosted: Tue Aug 14, 2012 8:03 am
by NicC
Links to Sort manuals are at the top of the DFSORT section of the forum - which is where they have always been. Links to the IBM Manuals in general are now provided at the top and bottom of every page.

Re: How to check for specific string in the file

PostPosted: Tue Aug 14, 2012 8:30 am
by dick scherrer
Hello,

One of the first things to do is Search in this part of the forum for similar topics. There are many topics that demonstrate using INCLUDE. There are some showing SS and this is not a good search value as it is too short (only 2 characters).

For complete info about substring (SS), refer to the manuals mentioned by Nic.

If you find smething that is not clear, post what you found and your doubt. Someone will be able to clarify.

Re: How to check for specific string in the file

PostPosted: Tue Aug 14, 2012 9:00 pm
by skolusu
You can use SS format like shown below to get the desired results. I assumed that your LRECL is 80 Bytes

//STEP0100 EXEC PGM=SORT                   
//SYSOUT   DD SYSOUT=*                     
//SORTIN   DD *                             
HEADER 11111111     TEXT    KEY             
4 JFJFJFJF   9 9 9 9 99                     
4GJGJGJGJ                  900D0D0D         
  8888     THIS IS A KEY                   
   8888 00S0S0S0S0                         
//SORTOUT  DD SYSOUT=*                     
//SYSIN    DD *                             
  SORT FIELDS=COPY                         
  INCLUDE COND=(1,80,SS,EQ,C'THIS IS A KEY')
//*

Re: How to check for specific string in the file

PostPosted: Tue Aug 14, 2012 9:32 pm
by Irene Ioujanina
Thank you!