botp
1/16/2008 2:13:00 AM
On Jan 16, 2008 9:04 AM, Junkone <junkone1@gmail.com> wrote:
> What is the fastest way to sort all the lines of a file alphabetically.
i cannot answer the question regarding "fastest" (to run, right?).
sometimes, my fastest means fastest solution i can come up with, but
not really fastest in speed. besides, things that are fast may not be
so easy to hack up with like eg you want to ignore blank lines and
lines with leading whitespace or special characters.
anyway i usually do it first on os level, like
C:\family\ruby>cat source | sort > sourcesorted
or in ruby, i usually use rio since it seems to take care of memory hogs,
C:\family\ruby>cat test.rb
require 'rubygems'
require 'rio'
rio("sourcesorted") < rio("source").readlines.sort
and there are of course better and cooler and more granular ways...
ymmv. just remember, in ruby, everything is possible in many ways :)
kind regards -botp