Pull random line from a file

Richard Lightman richard at nezumi.plus.com
Fri Sep 6 23:33:06 PDT 2002

* Björn Lindberg <d95-bli.no.spam at nada.kth.se> [2002-09-07 07:18]:
> I think Richard's one-pass awk solution is the most elegant one, but not
> necessarily the fastest. He has to generate a new random number for each
> line, and that might take longer than simply doing two passes through
> the file. I would guess that wc -l is pretty fast, although I haven't
> measured.
If this file is smaller than available memory, two passes are best.
I normally optimize for large amounts of data. You would only care
about speed on small files if you had thousands to process, and then
the best optimization is not to start the interpreter a thousand

Unsubscribe: send email to listar at linuxfromscratch.org
and put 'unsubscribe lfs-chat' in the subject header of the message

More information about the lfs-chat mailing list