View previous topic :: View next topic
Author
Message
nareshdacha New User Joined: 12 Jan 2010Posts: 66 Location: US
I have a input file as below
12345,testing testing,324
9876,new testing,6759
567,test,78963
24345, new testing testing,32433
Length of the each field may vary for each record, i need to sort this file.
based on 3rd field.
i need the output as specified below.....
12345 testing testing 324
9876 new testing 6759
567 test 78963
24345 new testing testing 32433
I have searched this but i got info for fixed length fields. In my case its variable length... By using SORT how to get the output.....
Suggest me how to proceed....
Back to top
Garry Carroll Senior Member Joined: 08 May 2006Posts: 1205 Location: Dublin, Ireland
Back to top
sqlcode1 Active Member Joined: 08 Apr 2010Posts: 577 Location: USA
nareshdacha,
nareshdacha wrote:
I have a input file as below
12345,testing testing,324
9876,new testing,6759
567,test,78963
24345, new testing testing,32433
Length of the each field may vary for each record, i need to sort this file.
based on 3rd field.
i need the output as specified below.....
12345 testing testing 324
9876 new testing 6759
567 test 78963
24345 new testing testing 32433
I have searched this but i got info for fixed length fields. In my case its variable length... By using SORT how to get the output.....
Suggest me how to proceed....
You indicated that you want output sorted on 3rd field but I don't see your expected output sorted in any order.
Also, are you trying to create fixed byte file from the input CSV file? If yes, then please provide length of each field.
Please use code tags to preserve original format.
Thanks,
Back to top
dick scherrer Moderator Emeritus Joined: 23 Nov 2006Posts: 19243 Location: Inside the Matrix
Hello,
Quote:
but I don't see your expected output sorted in any order.
The sample output is in order numerically by the 3rd field. . .
It just happens the input was already in sequence - not the best set of sample data. . .
Back to top
Garry Carroll Senior Member Joined: 08 May 2006Posts: 1205 Location: Dublin, Ireland
Quote:
have searched this but i got info for fixed length fields. In my case its variable length...
....and we would need to know the maximum length for each of the fields.
INREC PARSE=(%00=(ENDBEFR=C',',FIXLEN=??),
(%01=(ENDBEFR=C',',FIXLEN=??),
(%01=(ENDBEFR=C',',FIXLEN=??),
(
Back to top
sqlcode1 Active Member Joined: 08 Apr 2010Posts: 577 Location: USA
dick scherrer,
Unless I am missing any part of OP's post.
Quote:
The sample output is in order numerically by the 3rd field. . .
OP's expected output is
12345 testing testing 324
9876 new testing 6759
567 test 78963
24345 new testing testing 32433
If its sorted by 3rd field, shouldn't his last record, (3rd field =32433) appear before 3rd record (3rd field =78963)?
Thanks,
Back to top
dick scherrer Moderator Emeritus Joined: 23 Nov 2006Posts: 19243 Location: Inside the Matrix
Good catch - i'm eye-lexic today (in addition to being key-lexic). . .
Looked at it multiple times and convinced myself that there were only 4 digits in the 7xxx number.
Been one of those weeks. . .
d
Back to top
nareshdacha New User Joined: 12 Jan 2010Posts: 66 Location: US
Thanks Garry....
Thank to all.....
I have gone thru the Garry's link and i got the output.....
Here a small question here....
My input is...
12345,target testing,9876
3456,new testing,987612
45672,testing,56789
Output is....
12345target testing 9876
3456new testing 987612
45672testing 56789
how to get the leading zeroes for the numeric fields if that field has less than specified length...
I need the output as follows:
12345target testing 009876
03456new testing 987612
45672testing 056789
Sort Card:
SORT FIELDS=COPY
INREC PARSE=(%00=(ENDBEFR=C',',FIXLEN=5),
%01=(ENDBEFR=C',',FIXLEN=20),
%02=(FIXLEN=6)),
BUILD=(%00,%01,%02)
OUTREC BUILD=(1,5,SQZ=(SHIFT=RIGHT),6,20,26,6,SQZ=(SHIFT=RIGHT))
Can any suggest me ...........
Back to top
gcicchet Senior Member Joined: 28 Jul 2006Posts: 1702 Location: Australia
Hi,
try this
Code:
OUTREC BUILD=(1,5,SQZ=(SHIFT=RIGHT),6,20,26,6,UFF,M11,LENGTH=6)
Gerry
Back to top
nareshdacha New User Joined: 12 Jan 2010Posts: 66 Location: US
Thanks Gcicchet,it worked out......
Thanks to all for your suggestion.......
Back to top
nareshdacha New User Joined: 12 Jan 2010Posts: 66 Location: US
My input is
1st field length = 5
2nd field length= 20
3rd field length=6
-2345,target testing,-9
-345,testing testing data,-89
I got the output like this
02345target testing 000009
02345testing testing data 000089
instead of sign symbol i got the space....
Required Output:
-02345target testing-000009
-00345testing testing data-000089
I have used the below sort card..
SORT FIELDS=COPY
INREC PARSE=(%00=(ENDBEFR=C',',FIXLEN=5),
%01=(ENDBEFR=C',',FIXLEN=20),
%02=(FIXLEN=6)),
BUILD=(%00,%01,%02)
OUTREC BUILD=(1,5,UFF,EDIT=(STTTTT),SIGNS=(,'-','-','-'),6,20,
26,6,UFF,EDIT=(STTTTTT),SIGNS=(,'-','-','-'))
can anyone correct me..
Back to top
smijoss Active User Joined: 30 Aug 2007Posts: 114 Location: pune
a llittle research at your end, and u would have found out that
U of the UFF stands for UNSIGNED
for signed input u need to use SFF.
Back to top
Please enable JavaScript!