From: Ross Bamford Date: 2006-01-06T08:57:59+09:00 Subject: Re: How do you sort a text file? On Thu, 05 Jan 2006 21:28:08 -0000, wrote: > On Fri, 6 Jan 2006, Danny Abc wrote: > >> I'm new to Ruby and was wondering how to sort a text file? >> >> With UNIX scripts, I just use "cat input.txt | sort > output.txt". > > > open("output.txt"){|f| f.write IO::readlines("input.txt").sort} > > -a Alternatively, sticking with the command-line thing, how about: cat input.txt | ruby -e 'puts $stdin.sort' > output.txt -- Ross Bamford - rosco@roscopeco.remove.co.uk