in reply to Re: sort csv file on "date" column
in thread sort csv file on "date" column

Hi Jwkrahn, thanks a lot. The code you proposed looks so simple and doing the wor +k so nicely. Thanks again. Can you please describe the logic here if you dont mind? Regards, Manjunath Alcatel-Lucent

Replies are listed 'Best First'.
Re^3: sort csv file on "date" column
by jwkrahn (Abbot) on Apr 25, 2009 at 20:43 UTC

    The logic is to rearrange the date field (for example: 03/25/09) from month-day-year to year-month-day so it can be sorted by the built-in sort function without modification.   The algorithm employed is the GRT (Guttman-Rosler Transform) which prepends the reformatted date to the current record, sorts the current record, and then removes the reformatted date from the beginning of the current record.

      ok... I wanted to know what the numbers 6, [2,0,1] actually are. It he +lps me to customize the algorithm you provided if the date field is i +n other column. ~Manjunath

        In your CSV file the date is in the month-day-year order.   The regular expression captures those numbers using parentheses and returns a list of those three numbers in month-day-year order.   The list of numbers is rearranged using a list slice so that the year is moved to the front of the list.   So the original order of month-day-year (0,1,2) is changed to year-month-day (2,0,1).

        The date format used has every field as a two digit number so the combination of the year, month and day fields is a string 6 characters long.