Portal | Manuals | References | Downloads | Info | Programs | JCLs | Master the Mainframes
IBM Mainframe Computers Forums Index
 
Register
 
IBM Mainframe Computers Forums Index Mainframe: Search IBM Mainframe Forum: FAQ Memberlist Usergroups Profile Log in to check your private messages Log in
 

 

Parse a file to remove " and replace , with ~

 
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL
View previous topic :: :: View next topic  
Author Message
vineetjoshi01

New User


Joined: 06 Nov 2009
Posts: 14
Location: Singapore

PostPosted: Mon Jul 23, 2012 5:28 pm    Post subject: Parse a file to remove " and replace , with ~
Reply with quote

Hi All,

I have a file as mentioned in below sample. I need to parse this file and remove all the quotes " and have to replace all the commas , with ~ sign.

Input: The lenght of all the records are not same.

2004-10-12,"DOUGL",1724,1,"832702","M",4960,"O","20376361",1
2004-10-12,"DOU",1723,1,"161318","M",5119,"OW","20377946",1
2004-10-12,"DOUGLPA",1724,1,"832702","M",4960,"O","20376361",1

Output: The output should be as below

2004-10-12~DOUGL~1724~1~832702~M~4960~O~20376361~1
2004-10-12~DOU~1723~1~161318~M~5119~OW~20377946~1
2004-10-12~DOUGLPA~1724~1~832702~M~4960~O~20376361~1

Regards,
Vineet
Back to top
View user's profile Send private message

Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Mon Jul 23, 2012 5:49 pm    Post subject: Reply to: Parse a file to remove " and replace , with ~
Reply with quote

Please use the Code tags for your data.

Look at FINDREP in the manual. If I have understood correctly, it can do what you want.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Mon Jul 23, 2012 5:56 pm    Post subject:
Reply with quote

Hello,
This may work,
Code:

  OPTION COPY                                                       
  INREC FINDREP=(INOUT=(C'","',C'~',C',"',C'~',C'",',C'~',C',',C'~'))


Smart DFSORT tricks PDF has many useful and handy tricks with DFSORT. Give it a read, totally worth it.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Mon Jul 23, 2012 6:06 pm    Post subject: Reply to: Parse a file to remove " and replace , with ~
Reply with quote

Basically there, but will be simpler if all the quotes are removed first, then all the commas can be changed to tildes. C'' (a character string of no length) indicates the removal of the position occupied by that value. By default the record will be "shuffled" to the left.
Back to top
View user's profile Send private message
vasanthz

Global Moderator


Joined: 28 Aug 2007
Posts: 1445
Location: Azeroth

PostPosted: Mon Jul 23, 2012 6:11 pm    Post subject:
Reply with quote

Hello Bill,
You are right, I missed to notice that all fields are separated by , and " were expendable.
Code:
  INREC FINDREP=(INOUT=(C'"',C'',C',',C'~'))

Thanks for correction,
Back to top
View user's profile Send private message
vineetjoshi01

New User


Joined: 06 Nov 2009
Posts: 14
Location: Singapore

PostPosted: Tue Jul 24, 2012 12:39 pm    Post subject: Reply to: Parse a file to remove " and replace , with ~
Reply with quote

Hi Vasanth / Bill,

Thanks for your help!!! It worked fine!!!

Regards,
Vineet
Back to top
View user's profile Send private message
vineetjoshi01

New User


Joined: 06 Nov 2009
Posts: 14
Location: Singapore

PostPosted: Thu Aug 02, 2012 2:59 pm    Post subject:
Reply with quote

Hi Vasanth / Bill,

Could you please help further in this case. Actually I have got comma , as data in some of the record fields. For example "DOUGL,HARON" in below record. I do not want that , to be replaced with ~. So the input will be as follows:

2004-10-12,"DOUGL,HARON",1724,1,"832702","M",4960,"O","20376361",1
2004-10-12,"DOU",1723,1,"161318","M",5119,"OW","20377946",1
2004-10-12,"DOUGLPA",1724,1,"832702","M",4960,"O","20376361",1

Output should be as follows: The , is retained which is part of data but rest of the commas are replaced with ~ sign.

2004-10-12~DOUGL,HARON~1724~1~832702~M~4960~O~20376361~1
2004-10-12~DOU~1723~1~161318~M~5119~OW~20377946~1
2004-10-12~DOUGLPA~1724~1~832702~M~4960~O~20376361~1

Thanks and regards,
Vineet
Back to top
View user's profile Send private message
dbzTHEdinosauer

Global Moderator


Joined: 20 Oct 2006
Posts: 6966
Location: porcelain throne

PostPosted: Thu Aug 02, 2012 3:09 pm    Post subject:
Reply with quote

looks like you will have to go to parse using the PAIR option
and then BUILD, inserting the tilde between fields.
Back to top
View user's profile Send private message
Bill Woodger

DFSORT Moderator


Joined: 09 Mar 2011
Posts: 7232

PostPosted: Thu Aug 02, 2012 4:34 pm    Post subject: Reply to: Parse a file to remove " and replace , with ~
Reply with quote

That'll do it. You PARSE the fields using the comma as a delimiter. Those bounded by quotes, use PAIR to preserve any commas inside. Then BUILD your output, with the tilde between each field. Your quote-protected commas will be preserved that way.
Back to top
View user's profile Send private message
Skolusu

Senior Member


Joined: 07 Dec 2007
Posts: 2205
Location: San Jose

PostPosted: Thu Aug 02, 2012 10:18 pm    Post subject:
Reply with quote

vineetjoshi01,

Use the following DFSORT JCL which will give you the desired results. The trick here is to use FINDREP to replace the comma to a space and then use SQZ with PAIR=QUOTE to replace the space with ~. Once that is done we use another SQZ to replace the space within the name to comma. Finally we use another FINDREP to replace the double quotes.

Code:

//STEP0100 EXEC PGM=SORT                                           
//SYSOUT   DD SYSOUT=*                                             
//SORTIN   DD *                                                     
2004-10-12,"DOUGL,HARON",1724,1,"832702","M",4960,"O","20376361",1 
2004-10-12,"DOU",1723,1,"161318","M",5119,"OW","20377946",1         
2004-10-12,"DOUGLPA",1724,1,"832702","M",4960,"O","20376361",1     
//SORTOUT  DD SYSOUT=*                                 
//SYSIN    DD *                                       
  SORT FIELDS=COPY                                     
  INREC IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C',',C' '))),
  IFTHEN=(WHEN=INIT,                                   
  BUILD=(1,80,SQZ=(SHIFT=LEFT,PAIR=QUOTE,MID=C'~'))), 
  IFTHEN=(WHEN=INIT,                                   
  BUILD=(1,80,SQZ=(SHIFT=LEFT,MID=C','))),             
  IFTHEN=(WHEN=INIT,FINDREP=(INOUT=(C'"',C'')))       
//*
Back to top
View user's profile Send private message
View previous topic :: :: View next topic  
Post new topic   Reply to topic    IBMMAINFRAMES.com Support Forums -> DFSORT/ICETOOL All times are GMT + 6 Hours
Page 1 of 1

 

Search our Forum:

Similar Topics
Topic Author Forum Replies Posted
No new posts Add PD field from 2nd file to PD in 1st Sushant Garje DFSORT/ICETOOL 6 Thu Dec 01, 2016 4:32 pm
No new posts File Aid to File Manager conversion murali3955 IBM Tools 4 Thu Nov 24, 2016 3:41 pm
No new posts How to convert the VBM file to VB or... Sulabh Agrawal JCL & VSAM 4 Fri Nov 18, 2016 1:04 pm
No new posts CICS Roll back partially - Need to re... dwijadas CICS 4 Wed Nov 16, 2016 4:30 pm
No new posts Problem in writing Output file vickey_dw COBOL Programming 5 Mon Nov 14, 2016 11:14 pm


Facebook
Back to Top
 
Mainframe Wiki | Forum Rules | Bookmarks | Subscriptions | FAQ | Tutorials | Contact Us