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 specific string

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


Joined: 22 Dec 2002
Posts: 64
Topics: 28
Location: Chennai

PostPosted: Fri Mar 10, 2006 6:24 am    Post subject: Search for a specific string Reply with quote

Hi,

I tried to search for this one and did not egt any clue and hence posting the question !

We have one requirement. The sample input data is as follows.

123x4444
2x5555
x33444
1234555


The requirement is to copy all characters from 'x'. Output should look like

x4444
x5555
x33444

i.e, if the character 'x' is present in record, it should copy the characters beginning from 'x'. If 'x' is not found, then that record should be discarded in output.

Is there any SORT feature which will do this?

Assume that the file is FB with length 80 chars.

Thanks for any help.

Regards
Ranjish
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Mar 10, 2006 8:31 am    Post subject: Reply with quote

Ranjish,

If your shop has DFSORT then try this job(not tested).


Code:

//STEP0100 EXEC PGM=SORT
//SYSOUT   DD SYSOUT=*
//SORTIN   DD *
123X4444
2X5555
X33444
1234555
ABC
//SORTOUT  DD SYSOUT=*
//SYSIN    DD *
 SORT FIELDS=COPY
 INREC IFTHEN=(WHEN=(01,1,CH,EQ,C'X'),
               OVERLAY=(81:02,79,01X)),
       IFTHEN=(WHEN=(02,1,CH,EQ,C'X'),
               OVERLAY=(81:03,78,02X)),
       IFTHEN=(WHEN=(03,1,CH,EQ,C'X'),
               OVERLAY=(81:04,77,03X)),
       IFTHEN=(WHEN=(04,1,CH,EQ,C'X'),
               OVERLAY=(81:05,76,04X)),
       IFTHEN=(WHEN=(05,1,CH,EQ,C'X'),
               OVERLAY=(81:06,75,05X)),
       IFTHEN=(WHEN=(06,1,CH,EQ,C'X'),
               OVERLAY=(81:07,74,06X)),
       IFTHEN=(WHEN=(07,1,CH,EQ,C'X'),
               OVERLAY=(81:08,73,07X)),
       IFTHEN=(WHEN=(08,1,CH,EQ,C'X'),
               OVERLAY=(81:09,72,08X)),
       IFTHEN=(WHEN=(09,1,CH,EQ,C'X'),
               OVERLAY=(81:10,71,09X)),
       IFTHEN=(WHEN=(10,1,CH,EQ,C'X'),
               OVERLAY=(81:11,70,10X)),
       IFTHEN=(WHEN=(11,1,CH,EQ,C'X'),
               OVERLAY=(81:12,69,11X)),
       IFTHEN=(WHEN=(12,1,CH,EQ,C'X'),
               OVERLAY=(81:13,68,12X)),
       IFTHEN=(WHEN=(13,1,CH,EQ,C'X'),
               OVERLAY=(81:14,67,13X)),
       IFTHEN=(WHEN=(14,1,CH,EQ,C'X'),
               OVERLAY=(81:15,66,14X)),
       IFTHEN=(WHEN=(15,1,CH,EQ,C'X'),
               OVERLAY=(81:16,65,15X)),
       IFTHEN=(WHEN=(16,1,CH,EQ,C'X'),
               OVERLAY=(81:17,64,16X)),
       IFTHEN=(WHEN=(17,1,CH,EQ,C'X'),
               OVERLAY=(81:18,63,17X)),
       IFTHEN=(WHEN=(18,1,CH,EQ,C'X'),
               OVERLAY=(81:19,62,18X)),
       IFTHEN=(WHEN=(19,1,CH,EQ,C'X'),
               OVERLAY=(81:20,61,19X)),
       IFTHEN=(WHEN=(20,1,CH,EQ,C'X'),
               OVERLAY=(81:21,60,20X)),
       IFTHEN=(WHEN=(21,1,CH,EQ,C'X'),
               OVERLAY=(81:22,59,21X)),
       IFTHEN=(WHEN=(22,1,CH,EQ,C'X'),
               OVERLAY=(81:23,58,22X)),
       IFTHEN=(WHEN=(23,1,CH,EQ,C'X'),
               OVERLAY=(81:24,57,23X)),
       IFTHEN=(WHEN=(24,1,CH,EQ,C'X'),
               OVERLAY=(81:25,56,24X)),
       IFTHEN=(WHEN=(25,1,CH,EQ,C'X'),
               OVERLAY=(81:26,55,25X)),
       IFTHEN=(WHEN=(26,1,CH,EQ,C'X'),
               OVERLAY=(81:27,54,26X)),
       IFTHEN=(WHEN=(27,1,CH,EQ,C'X'),
               OVERLAY=(81:28,53,27X)),
       IFTHEN=(WHEN=(28,1,CH,EQ,C'X'),
               OVERLAY=(81:29,52,28X)),
       IFTHEN=(WHEN=(29,1,CH,EQ,C'X'),
               OVERLAY=(81:30,51,29X)),
       IFTHEN=(WHEN=(30,1,CH,EQ,C'X'),
               OVERLAY=(81:31,50,30X)),
       IFTHEN=(WHEN=(31,1,CH,EQ,C'X'),
               OVERLAY=(81:32,49,31X)),
       IFTHEN=(WHEN=(32,1,CH,EQ,C'X'),
               OVERLAY=(81:33,48,32X)),
       IFTHEN=(WHEN=(33,1,CH,EQ,C'X'),
               OVERLAY=(81:34,47,33X)),
       IFTHEN=(WHEN=(34,1,CH,EQ,C'X'),
               OVERLAY=(81:35,46,34X)),
       IFTHEN=(WHEN=(35,1,CH,EQ,C'X'),
               OVERLAY=(81:36,45,35X)),
       IFTHEN=(WHEN=(36,1,CH,EQ,C'X'),
               OVERLAY=(81:37,44,36X)),
       IFTHEN=(WHEN=(37,1,CH,EQ,C'X'),
               OVERLAY=(81:38,43,37X)),
       IFTHEN=(WHEN=(38,1,CH,EQ,C'X'),
               OVERLAY=(81:39,42,38X)),
       IFTHEN=(WHEN=(39,1,CH,EQ,C'X'),
               OVERLAY=(81:40,41,39X)),
       IFTHEN=(WHEN=(40,1,CH,EQ,C'X'),
               OVERLAY=(81:41,40,40X)),
       IFTHEN=(WHEN=(41,1,CH,EQ,C'X'),
               OVERLAY=(81:42,39,41X)),
       IFTHEN=(WHEN=(42,1,CH,EQ,C'X'),
               OVERLAY=(81:43,38,42X)),
       IFTHEN=(WHEN=(43,1,CH,EQ,C'X'),
               OVERLAY=(81:44,37,43X)),
       IFTHEN=(WHEN=(44,1,CH,EQ,C'X'),
               OVERLAY=(81:45,36,44X)),
       IFTHEN=(WHEN=(45,1,CH,EQ,C'X'),
               OVERLAY=(81:46,35,45X)),
       IFTHEN=(WHEN=(46,1,CH,EQ,C'X'),
               OVERLAY=(81:47,34,46X)),
       IFTHEN=(WHEN=(47,1,CH,EQ,C'X'),
               OVERLAY=(81:48,33,47X)),
       IFTHEN=(WHEN=(48,1,CH,EQ,C'X'),
               OVERLAY=(81:49,32,48X)),
       IFTHEN=(WHEN=(49,1,CH,EQ,C'X'),
               OVERLAY=(81:50,31,49X)),
       IFTHEN=(WHEN=(50,1,CH,EQ,C'X'),
               OVERLAY=(81:51,30,50X)),
       IFTHEN=(WHEN=(51,1,CH,EQ,C'X'),
               OVERLAY=(81:52,29,51X)),
       IFTHEN=(WHEN=(52,1,CH,EQ,C'X'),
               OVERLAY=(81:53,28,52X)),
       IFTHEN=(WHEN=(53,1,CH,EQ,C'X'),
               OVERLAY=(81:54,27,53X)),
       IFTHEN=(WHEN=(54,1,CH,EQ,C'X'),
               OVERLAY=(81:55,26,54X)),
       IFTHEN=(WHEN=(55,1,CH,EQ,C'X'),
               OVERLAY=(81:56,25,55X)),
       IFTHEN=(WHEN=(56,1,CH,EQ,C'X'),
               OVERLAY=(81:57,24,56X)),
       IFTHEN=(WHEN=(57,1,CH,EQ,C'X'),
               OVERLAY=(81:58,23,57X)),
       IFTHEN=(WHEN=(58,1,CH,EQ,C'X'),
               OVERLAY=(81:59,22,58X)),
       IFTHEN=(WHEN=(59,1,CH,EQ,C'X'),
               OVERLAY=(81:60,21,59X)),
       IFTHEN=(WHEN=(60,1,CH,EQ,C'X'),
               OVERLAY=(81:61,20,60X)),
       IFTHEN=(WHEN=(61,1,CH,EQ,C'X'),
               OVERLAY=(81:62,19,61X)),
       IFTHEN=(WHEN=(62,1,CH,EQ,C'X'),
               OVERLAY=(81:63,18,62X)),
       IFTHEN=(WHEN=(63,1,CH,EQ,C'X'),
               OVERLAY=(81:64,17,63X)),
       IFTHEN=(WHEN=(64,1,CH,EQ,C'X'),
               OVERLAY=(81:65,16,64X)),
       IFTHEN=(WHEN=(65,1,CH,EQ,C'X'),
               OVERLAY=(81:66,15,65X)),
       IFTHEN=(WHEN=(66,1,CH,EQ,C'X'),
               OVERLAY=(81:67,14,66X)),
       IFTHEN=(WHEN=(67,1,CH,EQ,C'X'),
               OVERLAY=(81:68,13,67X)),
       IFTHEN=(WHEN=(68,1,CH,EQ,C'X'),
               OVERLAY=(81:69,12,68X)),
       IFTHEN=(WHEN=(69,1,CH,EQ,C'X'),
               OVERLAY=(81:70,11,69X)),
       IFTHEN=(WHEN=(70,1,CH,EQ,C'X'),
               OVERLAY=(81:71,10,70X)),
       IFTHEN=(WHEN=(71,1,CH,EQ,C'X'),
               OVERLAY=(81:72,09,71X)),
       IFTHEN=(WHEN=(72,1,CH,EQ,C'X'),
               OVERLAY=(81:73,08,72X)),
       IFTHEN=(WHEN=(73,1,CH,EQ,C'X'),
               OVERLAY=(81:74,07,73X)),
       IFTHEN=(WHEN=(74,1,CH,EQ,C'X'),
               OVERLAY=(81:75,06,74X)),
       IFTHEN=(WHEN=(75,1,CH,EQ,C'X'),
               OVERLAY=(81:76,05,75X)),
       IFTHEN=(WHEN=(76,1,CH,EQ,C'X'),
               OVERLAY=(81:77,04,76X)),
       IFTHEN=(WHEN=(77,1,CH,EQ,C'X'),
               OVERLAY=(81:78,03,77X)),
       IFTHEN=(WHEN=(78,1,CH,EQ,C'X'),
               OVERLAY=(81:79,02,78X)),
       IFTHEN=(WHEN=(79,1,CH,EQ,C'X'),
               OVERLAY=(81:80,01,79X)),
       IFTHEN=(WHEN=(80,1,CH,EQ,C'X'),
               OVERLAY=(81:80X )),
       IFTHEN=(WHEN=NONE,
               OVERLAY=(81:80X ))
  OUTFIL OMIT=(81,80,CH,EQ,C'X'),
  OUTREC=(81,80)
/*


Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
German Castillo
Beginner


Joined: 23 Dec 2005
Posts: 83
Topics: 2
Location: Caracas, Venezuela

PostPosted: Fri Mar 10, 2006 9:06 am    Post subject: Reply with quote

Try this:

Code:

/* REXX */               
Address ISREDIT           
"MACRO"                   
"X all"                   
"F 'x' all"               
"DEL all X"               
"(zl) = linenum .ZLAST"   
Do I = 1 to ZL           
  "(Line) = line" I       
  Parse Var Line ."x"rest
  Say rest    /* Or write it to a file */           
End                       
"BUILTIN CANCEL"         

_________________
Best wishes,

German Castillo
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: Fri Mar 10, 2006 12:41 pm    Post subject: Reply with quote

Kolusu,

Your IFTHEN job won't work (I know you can't test it because you don't have DFSORT). But a simpler DFSORT job with IFTHEN like this will work:

Code:

//S1    EXEC  PGM=ICEMAN
//SYSOUT    DD  SYSOUT=*
//SORTIN DD *
123x4444
2x5555
x33444
1234555
/*
//SORTOUT DD SYSOUT=*
//SYSIN    DD    *
  SORT FIELDS=COPY
  INCLUDE COND=(1,80,SS,EQ,C'x')
  INREC IFTHEN=(WHEN=(01,1,CH,EQ,C'x'),
                BUILD=(1,80)),
        IFTHEN=(WHEN=(02,1,CH,EQ,C'x'),
                BUILD=(2,79)),
        IFTHEN=(WHEN=(03,1,CH,EQ,C'x'),
                BUILD=(3,78)),
        IFTHEN=(WHEN=(04,1,CH,EQ,C'x'),
                BUILD=(4,77)),
        ...
        IFTHEN=(WHEN=(80,1,CH,EQ,C'x'),
                BUILD=(80,1))
/*

_________________
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
Ranjish
Beginner


Joined: 22 Dec 2002
Posts: 64
Topics: 28
Location: Chennai

PostPosted: Tue Mar 14, 2006 8:36 am    Post subject: Reply with quote

Thanks for the replies.

The DFSORT solution seems to be fine, but the SORT step will become huge and if there is a change in file length, I need to change the SYSIN again.

Currently, we are using REXX for the same and would like to know if there will be significant improvement if we switch over to SORT.

Regards
Ranjish
Back to top
View user's profile Send private message
Mervyn
Moderator


Joined: 02 Dec 2002
Posts: 415
Topics: 6
Location: Hove, England

PostPosted: Tue Mar 14, 2006 9:49 am    Post subject: Reply with quote

It's not all that likely that you have SELCOPY. If you did, this would work for you:

Code:

//STEP010  EXEC PGM=SELCOPY                                     
//SYSPRINT DD   SYSOUT=*                                       
//OUTFILE  DD   SYSOUT=*                                       
//SYSIN    DD   *                                               
OPTION WORKLEN 160       * WORKLEN NEEDS TO BE DOUBLE LRECL     
READ INFILE                                                     
IF POS ANY = X                                                 
THEN WRITE OUTFILE FROM @                                       
THEN POS 1 = ' '                                               
THEN MOVE 159 FROM 1 TO 2                                       
//INFILE   DD    *                                             
123X4444                                                       
2X5555                                                         
X33444                                                         
1234555                                                         
123X4444                                                       
2X5555                                                         
X33444                                                         
1234555     



Output is:

                                                   
********************************* TOP OF DATA ***
X4444                                           
X5555                                           
X33444                                           
X4444                                           
X5555                                           
X33444                                           
******************************** BOTTOM OF DATA *


I know DFSORT can do the search part. Is it really not possible to write from there?
_________________
The day you stop learning the dinosaur becomes extinct
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: Thu Apr 20, 2006 4:33 pm    Post subject: Reply with quote

The PARSE function of z/OS DFSORT V1R5 PTF UK90007 or DFSORT R14 PTF UK90006 (April, 2006) lets you do this kind of thing quite easily. No need for all those IFTHEN clauses. Here's the DFSORT job:

Code:

//S1 EXEC PGM=ICEMAN
//SYSOUT DD SYSOUT=*
//SORTIN DD DSN=...  input file (FB/80)
//SORTOUT DD DSN=...  output file (FB/80)
//SYSIN DD *'
  OPTION COPY
  INCLUDE COND=(1,80,SS,EQ,C'x')
  INREC PARSE=(%00=(STARTAT=C'x',FIXLEN=80)),
   BUILD=(%00)
/*


PARSE extracts the characters starting at 'x' (wherever 'x' starts) to the 80-byte %00 parsed field. BUILD creates a record with the %00 field.

For complete details on the many things you can do with PARSE and %nn, see:

www.ibm.com/servers/storage/support/software/sort/mvs/peug/
_________________
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
js01
Beginner


Joined: 13 Oct 2005
Posts: 84
Topics: 32
Location: INDIA

PostPosted: Fri Aug 04, 2006 2:25 pm    Post subject: Reply with quote

Frank,

when i try above solution , got Syntax error as below,
can you please help me.

Also tried SELCOPY option it is working fine, but i do not know much about SELCOPY
Code:

SYSIN :                                       
 OPTION COPY                                 
 INCLUDE COND=(1,80,SS,EQ,C'X')               
 INREC PARSE=(%00=(STARTAT=C'X',FIXLEN=80)), 
       *                                     
  BUILD=(%00)                                 
WER268A  INREC STATEMENT   : SYNTAX ERROR     
WER211B  SYNCSMF  CALLED BY SYNCSORT; RC=0000
WER449I  SYNCSORT GLOBAL DSM SUBSYSTEM ACTIVE

****************

below is the SYSIN

//SYSIN DD *                                     
 OPTION COPY                                     
 INCLUDE COND=(1,80,SS,EQ,C'X')                   
 INREC PARSE=(%00=(STARTAT=C'X',FIXLEN=80)),     
  BUILD=(%00)                                     
/*     

Thank you
Back to top
View user's profile Send private message
kolusu
Site Admin
Site Admin


Joined: 26 Nov 2002
Posts: 12378
Topics: 75
Location: San Jose

PostPosted: Fri Aug 04, 2006 2:42 pm    Post subject: Reply with quote

js01,

You are using syncsort which does NOT Support PARSE which is a part of the latest PTF from DFSORT.

Check this link for documentation of SELCOPY

http://www.cbl.com/selcdl.html

Hope this helps...

Cheers

Kolusu
_________________
Kolusu
www.linkedin.com/in/kolusu
Back to top
View user's profile Send private message Send e-mail Visit poster's website
semigeezer
Supermod


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

PostPosted: Fri Aug 04, 2006 4:40 pm    Post subject: Reply with quote

If you have the space, you can copy it to USS and just use
Code:
grep "x" testdata | sed 's/.*x/x/g'>newfile


The whole thing plus a call to browse is:
Code:
/* rexx */                                             
                                                       
"OPUT 'USERID.TESTDATA' 'testdata'"                     
"OSHELL grep ""x""  testdata | sed 's/.*x/x/g' > outfile"
"OGET 'outfile' outfile"                               
address ispexec "browse dataset(outfile)"


This is fine for a simple case like this. I suspect your real data is more complicated than just an x though
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 -> 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