in reply to sort csv file on "date" column

$ echo '"Add workflow, Delete workflow",resource1,Sat 04/25/09,manager +1 "Updateworkflow, Delete workflow",resource2,Wed 04/15/09,manager2 "Retrieve workflow, Delete workflow",resource3,Sat 04/25/09,manager3 "Add workflow, Delete workflow",resource4,Wed 03/25/09,manager4 "Add workflow",resource5,Tue 04/14/09,manager5' | \ perl -e' print for map substr( $_, 6 ), sort map join( "", ( m<,\w{3} (\d\d)/(\d\d)/(\d\d),> )[ 2,0,1 ] +, $_ ), <> ' "Add workflow, Delete workflow",resource4,Wed 03/25/09,manager4 "Add workflow",resource5,Tue 04/14/09,manager5 "Updateworkflow, Delete workflow",resource2,Wed 04/15/09,manager2 "Add workflow, Delete workflow",resource1,Sat 04/25/09,manager1 "Retrieve workflow, Delete workflow",resource3,Sat 04/25/09,manager3

Replies are listed 'Best First'.
Re^2: sort csv file on "date" column
by mbm (Novice) on Apr 25, 2009 at 16:51 UTC
    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

      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