Hi
I have requirement like
File contains
abc 002
bcd 001
cde 004
abc 003
xyz 008
output
abc 003
bcd 001
cde 004
xyz 008
My intenion is to copy all the records in the file and for the duplicates i want the last record of the duplicate occurance record. here the key is first three letters.
I want this by using syncsort commands is it possible?
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
You could add a sequence number to each record, then SORT on your key, followed by the sequence-number, descending, do the SUM, and remove the sequence number in OUTREC.
If you don't want to SORT (maybe the file is "big") then either of the two techniques here can be applied to what you want.
Joined: 09 Mar 2011 Posts: 7309 Location: Inside the Matrix
-3nadh,
Presumably, as has already been mentioned recently, you have "EQUALS" as your installation option.
However, for solutions which require EQUALS, it would be good to use it explicitly, as not all sites have that as their default (I have added it to your code).
For SyncSort prior to 1.4, you could try this to get the last record of equal keys:
I have left the symbols/SYMNAMES in to leave the code as "generic". For different fixed-length records, simply adjust the length of the record, and the start position (if necessary), and length of the key.
Without the symbols, the code looks like this (for the first):