Re: Sort Multidimensional Array by Column 5
Re: Sort Multidimensional Array by Column 5
- Subject: Re: Sort Multidimensional Array by Column 5
- From: Matt Neuburg <email@hidden>
- Date: Tue, 05 Oct 2010 12:30:56 -0700
- Thread-topic: Sort Multidimensional Array by Column 5
On Tue, 5 Oct 2010 16:29:28 +0100, Richard Lake
<email@hidden> said:
>I am returning to an old issue from this summer that never got resolved,
>it involves reading a .csv file into an array, sorting the array by a
>column and then writing the array back to disc. The input and output
>delimited must be retained always.
Here's a simple-minded Ruby one-liner that works on the data you provided:
result = s.split("\n").collect{|line| line.split(",")}.sort{|a,b| a[4] <=>
b[4]}
Of course CSV can be complicated, in which case you'd want to use one of
the existing libraries to parse the data into arrays; but the point is
that sorting a multidimensional array on the 5th column of the inner
arrays is trivial. m.
_______________________________________________
Do not post admin requests to the list. They will be ignored.
AppleScript-Users mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
Archives: http://lists.apple.com/archives/applescript-users
This email sent to email@hidden