Go4Expert

Go4Expert (http://www.go4expert.com/)
-   C (http://www.go4expert.com/forums/c/)
-   -   sorting on the basis of datetime (http://www.go4expert.com/forums/sorting-basis-datetime-t23855/)

heidik 12Nov2010 15:10

sorting on the basis of datetime
 
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?

heidik 12Nov2010 15:11

Re: sorting on the basis of datetime
 
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?

xpi0t0s 13Nov2010 13:20

Re: sorting on the basis of datetime
 
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.

heidik 15Nov2010 21:34

Re: sorting on the basis of datetime
 
Thanks xpi0t0s :)


All times are GMT +5.5. The time now is 16:50.