sort lines alpahetically

B

botp

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
 
H

Heinrich Piard

Junkone said:
What is the fastest way to sort all the lines of a file alphabetically.

Hi Junkone,

I would suggest to use something like this:

SortedFile = File.readlines('c:\ruby_scripts\test.txt.txt').sort

puts SortedFile



bye
Henry
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,271
Latest member
BuyAtenaLabsCBD

Latest Threads

Top