Search for a string using SORT

2 views
Skip to first unread message

MF Tips

unread,
Feb 7, 2006, 9:28:48 PM2/7/06
to
To Search for a particular string within a file when the exact position of that string within a record is not known and to write that record in the Output file the following SORT card can be used.

Example 1:
SORT FIELDS=COPY
INCLUDE COND= (1, 80, SS, EQ, C'FIND STRING')

Here,

SS - Sub string,
1 - Starting position of the range
80 - Width of the search range
EQ - Comparison operators

The Sort card for this will need information like range of columns within which you want the search to be performed. To search in the whole file you can give the start position as 1 and LRECL of the file as the width of the search range as done above. We can also replace the 'EQ' parameter by 'NE' which will fetch us all the records which don't have the specified string. Only EQ & NE can be used for comparison. We can even use OMIT COND instead of INCLUDE.

This can also be used to find the records with string that match one of the strings in the COND.

Example 2:
SORT FIELDS=COPY
INCLUDE COND= (1, 80, SS, EQ, C'HDR,TRL')

The above sort card returns all records with the substring ' HDR' or 'TRL' occurring within the search range(1-80) of the record in the input file.
 
Thanks,
MFTIPS
Reply all
Reply to author
Forward
0 new messages