D
Danny Abc
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".
With UNIX scripts, I just use "cat input.txt | sort > output.txt".
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
Danny said: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".
Danny said: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".
Robert said:You are entitled to the "useless cat award".
Any reason why you don't
just do
"sort input.txt > output.txt"?
Hal said:My neighbor's cat won that already.
Regarding his original question, I think if he has large files to
sort, he might be well off just using the Unix sort utility. If he
has complex logic, of course, he can still control it all in Ruby.
+1
I haven't tested it, but I can't help expecting that on a large
file, system("sort...") would be the efficient way.
Michal said:Well, cat does not write its arguments so you are pretty sure it is
the input argument whatever command you put next in the pipeline.
Plus there was a shell once where input redirection did not work and
one replaced it with cat and |. At least that is how I learned to use
useless cats extensively.
Anyway, cats are nice
Certainly! See http://www.flickr.com/photos/99776024@N00/sets/
1697461/
J. Ryan Sobol said:
Danny said: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".
Danny> I'm new to Ruby and was wondering how to sort a text file?
Danny> With UNIX scripts, I just use "cat input.txt | sort > output.txt".
Why not sort <input.txt >output.txt?
That cat is totally superfluous.
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.