|
View previous topic :: View next topic
|
| Author |
Message |
vineetjoshi01
New User
Joined: 06 Nov 2009 Posts: 14 Location: Singapore
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
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 |
|
 |
vasanthz
Global Moderator

Joined: 28 Aug 2007 Posts: 1753 Location: Tirupur, India
|
|
|
|
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 |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| 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 |
|
 |
vasanthz
Global Moderator

Joined: 28 Aug 2007 Posts: 1753 Location: Tirupur, India
|
|
|
|
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 |
|
 |
vineetjoshi01
New User
Joined: 06 Nov 2009 Posts: 14 Location: Singapore
|
|
|
|
Hi Vasanth / Bill,
Thanks for your help!!! It worked fine!!!
Regards,
Vineet |
|
| Back to top |
|
 |
vineetjoshi01
New User
Joined: 06 Nov 2009 Posts: 14 Location: Singapore
|
|
|
|
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 |
|
 |
dbzTHEdinosauer
Global Moderator

Joined: 20 Oct 2006 Posts: 6965 Location: porcelain throne
|
|
|
|
looks like you will have to go to parse using the PAIR option
and then BUILD, inserting the tilde between fields. |
|
| Back to top |
|
 |
Bill Woodger
Moderator Emeritus
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
|
|
|
|
| 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 |
|
 |
Skolusu
Senior Member
Joined: 07 Dec 2007 Posts: 2205 Location: San Jose
|
|
|
|
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 |
|
 |
|
|
 |
All times are GMT + 6 Hours |
|