sorting on the basis of datetime

heidik's Avatar, Join Date: Oct 2010
Contributor
I have a file that has duplicates and I have to select the one with the earliest time

0:1:OrderReceive,01.07.2010 10:38:09.984,0G508Q090,0000F9F5,A,15,0,15,0,115
0:1:OrderReceive,01.07.2010 10:30:36.903,0G508Q090,0000F9F5,A,15,0,15,0,115

0:2:OrderReceive,01.07.2010 10:23:58.390,0G508Q086,0000F9DA,A,15,0,15,0,70
0:2:OrderReceive,01.07.2010 10:16:25.340,0G508Q086,0000F9DA,A,15,0,15,0,70
where first two lines are identical except the time part and the last two lines are identical but again except for its time part. I need to select the second line of each pair (because they have the earliest time) and the final output should be
0:1:OrderReceive,01.07.2010 10:30:36.903,0G508Q090,0000F9F5,A,15,0,15,0,115
0:2:OrderReceive,01.07.2010 10:16:25.340,0G508Q086,0000F9DA,A,15,0,15,0,70
could anyone please help?
0
heidik's Avatar, Join Date: Oct 2010
Contributor
I have a file that has duplicates and I have to select the one with the earliest time
Code:
0:1:OrderReceive,01.07.2010 10:38:09.984,0G508Q090,0000F9F5,A,15,0,15,0,115
0:1:OrderReceive,01.07.2010 10:30:36.903,0G508Q090,0000F9F5,A,15,0,15,0,115

0:2:OrderReceive,01.07.2010 10:23:58.390,0G508Q086,0000F9DA,A,15,0,15,0,70
0:2:OrderReceive,01.07.2010 10:16:25.340,0G508Q086,0000F9DA,A,15,0,15,0,70
where first two lines are identical except the time part and the last two lines are identical but again except for its time part. I need to select the second line of each pair (because they have the earliest time) and the final output should be
Code:
0:1:OrderReceive,01.07.2010 10:30:36.903,0G508Q090,0000F9F5,A,15,0,15,0,115
0:2:OrderReceive,01.07.2010 10:16:25.340,0G508Q086,0000F9DA,A,15,0,15,0,70
could anyone please help?
0
xpi0t0s's Avatar, Join Date: Aug 2004
Mentor
Are the duplicates guaranteed to be next to each other?
If so, then just read it in line by line. Store the first line in a "selected" string; if it's the only one then by definition it's earlier. Read the next line, if it's earlier than the first then copy that line to "selected", and if it's not a duplicate then you're onto the next set. Repeat until you get to the end of the duplicates, then start over for the next set.
0
heidik's Avatar, Join Date: Oct 2010
Contributor
Thanks xpi0t0s