Submit Hint Search The Forums LinksStatsPollsHeadlinesRSS
14,000 hints and counting!


Click here to return to the 'No need for sed' hint
The following comments are owned by whoever posted them. This site is not responsible for what they say.
No need for sed
Authored by: müzso on May 14, '07 11:32:51PM
You can go even more environment friendlier, than that ... :-) No need for sed if you already start awk ... and no need to read the file twice.
awk "{ lines[NR] = $0 } END { print lines[$RANDOM % NR + 1] }" /path/to/quotes.txt

And if you're interested in various other solutions (eg. Perl :-) ), then check out this thread.

[ Reply to This | # ]
No need for sed
Authored by: müzso on May 14, '07 11:37:31PM

Of course one should choose the solution that suites her/him better ... eg. if you've got a quotes.txt of some GB in size, then caching the lines in an array might make your os swap a little bit ... ;-)



[ Reply to This | # ]