On Sun, Aug 22, 2004 at 02:35:14PM -0500, Lance Hoffmeyer wrote:
Hello all,
I would like to write a script that will select N number of random lines in a file. Any suggestions on how to do this?
Here's one that prints random lines of files, ensuring not to overshoot the known length of the number of lines in the file:
sed -n $[ $RANDOM % $(wc -l < $FILE) + 1 ],$[ $RANDOM % $(wc -l < ./foo) + 1 ]p $FILE
Where $FILE is the filename. If you want to control the number of lines it will print, change the values. :)
-- Thomas Adam
That only prints one line whenever the second range number is less than the first[which happens roughly half the time][ignoring the fact that ./foo should also be $FILE].
signature.asc
Description: OpenPGP digital signature