[NTLUG:Discuss] Bash script question
Patrick R. Michaud
pmichaud at pobox.com
Wed Jan 19 14:54:16 CST 2005
On Wed, Jan 19, 2005 at 01:45:37PM -0700, Patrick R. Michaud wrote:
> On Wed, Jan 19, 2005 at 02:09:47PM -0600, Lance Simmons wrote:
> How about something like:
>
> for i in $(seq 1 40)
> do
> LINE=$(($RANDOM % 100 + 1));
> head -$LINE infile | tail -1
> done
I should also note, depending on the "evenness" of the numbers produced
by $RANDOM, the first 68 lines of the file are 1/327th more likely to
be chosen than the last 32 lines of the file, if that sort of
skew is important to you. It can be corrected, but I was just going with
a very simple solution to start. :-)
Pm
More information about the Discuss
mailing list