View previous topic :: View next topic
|
Author |
Message |
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Hi All,
I tries to search on forum for this requirement but could not find appropriate post.
My input file is as below
Code: |
TestA, testA1 testA2 testA3
TestB, testB1 testB2
TestC, testC1 testC2 testC3 TestC4 |
And I need output file as below
Code: |
TestA testA3
TestB testB2
TestC TestC4 |
Basically I want to copy only first and last word from records. Its FB file of length 40.
is it possible to do with Syncsort?
Thanks,
Chandan |
|
Back to top |
|
|
RahulG31
Active User
Joined: 20 Dec 2014 Posts: 446 Location: USA
|
|
|
|
It should Not be too difficult with PARSE considering the LRECL is only 40 bytes so you can fit in only a few words:
Code: |
INREC IFTHEN=(WHEN=INIT,PARSE=(%00=(ENDBEFR=C', ',FIXLEN=10),
%01=(ENDBEFR=C' ',FIXLEN=10),
%02=(ENDBEFR=C' ',FIXLEN=10),
%03=(ENDBEFR=C' ',FIXLEN=10),
%04=(FIXLEN=10)),BUILD=(%00,%01,%02,%03,%04)),
IFTHEN=(WHEN=(41,1,CH,NE,C' '),
BUILD=(%00,C' ',%04)),
IFTHEN=(WHEN=(31,1,CH,NE,C' '),
BUILD=(%00,C' ',%03)),
IFTHEN=(WHEN=(21,1,CH,NE,C' '),
BUILD=(%00,C' ',%02)),
IFTHEN=(WHEN=(11,1,CH,NE,C' '),
BUILD=(%00,C' ',%01))
OPTION COPY |
It may Not be the best solution but you can work from here.
If you are concerned about the spaces then you may use FINDREP=(INOUT=(C' ',C'~') and JFY=(SHIFT=RIGHT) and SQZ=(SHIFT=LEFT) wherever needed.
. |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2010 Location: USA
|
|
|
|
Can be enhanced, to make the code more flexible, to handle free-text input.
RahulG31 wrote: |
Code: |
INREC IFTHEN=(WHEN=INIT,
PARSE=(%00=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10),
%01=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10),
%02=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10),
%03=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10),
%04=(STARTAT=NONBLANK,ENDBEFR=C',',ENDBEFR=BLANKS,FIXLEN=10)),
BUILD=(%00,%01,%02,%03,%04)),
IFTHEN=(WHEN=(41,1,CH,NE,C' '),
BUILD=(%00,C' ',%04)),
IFTHEN=(WHEN=(31,1,CH,NE,C' '),
BUILD=(%00,C' ',%03)),
IFTHEN=(WHEN=(21,1,CH,NE,C' '),
BUILD=(%00,C' ',%02)),
IFTHEN=(WHEN=(11,1,CH,NE,C' '),
BUILD=(%00,C' ',%01))
OPTION COPY
END |
|
|
|
Back to top |
|
|
chandan.inst
Active User
Joined: 03 Nov 2005 Posts: 275 Location: Mumbai
|
|
|
|
Thanks for the reply guys.
I will try this. Only issue I didn't highlight in original post is my input words can be of different length.
But I will check with these solutions. it should work |
|
Back to top |
|
|
sergeyken
Senior Member
Joined: 29 Apr 2008 Posts: 2010 Location: USA
|
|
|
|
chandan.inst wrote: |
Only issue I didn't highlight in original post is my input words can be of different length. |
PARSE= will handle different length. Furthermore, STARTAFT=BLANKS,ENDBEFR=BLANKS will take care of any number of separating blanks.
You may need to set FIXLEN= to the maximum possible word length.
In the output record, you can use parameters JFY= and/or SQZ= to truncate unneeded blanks in output record. |
|
Back to top |
|
|
|
|