From: Eric Hodel Date: 2007-08-12T08:53:27+09:00 Subject: Re: Sorting a logfile, how would you write it? On Aug 11, 2007, at 15:25, William James wrote: > On Aug 10, 11:19 pm, Ryan Davis wrote: >> On Aug 10, 2007, at 13:54 , William James wrote: >>> File.open( ARGV.first, "r+" ){|file| >>> array = file.readlines >>> file.rewind >>> file.truncate(0) >>> file.puts array.sort_by{|s| s[/^\d+/].to_i } >>> } >> >> your version takes a lot of memory, > > Wrong. This method uses at least 2x the file size worth of memory. That's a lot. > E:\Ruby>ruby -e 'path = ARGV.shift; system %(sort -n "#{path}" >> "#{path}.tmp"); File.rename "#{path}.tmp", path' data > -e:1: unterminated string meets end of file I just ran it, it worked fine. You'll probably have to redo the quoting for a non-bourne-compatible shell. > Perhaps your attempt at a solution requires Unix, and you, > in your ignorance, or your thoughtlessness, or your > ignorance and your thoughtlessness, assumed that every > user of Ruby is a user of Unix. Please try to flame harder. This one just made me chuckle. -- Poor workers blame their tools. Good workers build better tools. The best workers get their tools to do the work for them. -- Syndicate Wars