Pull random line from a file

Rob Park rbpark at ualberta.ca
Fri Sep 6 14:05:17 PDT 2002

Alas! Kevan Shea spake thus:
> Hell with that I can do it in one line:
> RNDLINE=$(sed -n $(expr $RANDOM % $(grep -c --regexp=.* $FILENAME))p $FILENAME)

This is probably better:

RNDLINE=$(sed -n $(expr $RANDOM % $(wc -l $FILENAME))p $FILENAME)

Rob 'Feztaa' Park
The seven year itch comes from fooling around during the fourth, fifth,
and sixth years.
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