[ale] Bash question
Andrew Grimmke
grimmke at directvinternet.com
Thu Sep 5 10:01:10 EDT 2002
Danny Cox wrote:
>
> Joseph,
>
> On Wed, 2002-09-04 at 18:16, Joseph Mugerwa wrote:
> 1. i created a file where to keep all the mails to my
freinds
> 2. i have kept all the jokes in one file text format
> and every next joke is separeted with =* sign i.e
> =*
> joke n1
> blabla xxxxxxxxxxxxx
>
> =*
> joke n2
> blabla xxxxxxxxxxxxx
>
<snip>
>
> Here's some ideas that'll get you going in the right
> direction.
>
> 1) use wc to count the # of jokes:
>
> NLINES=$(grep '^=\*$' jokefile | wc -l)
>
> 2) use bash's built-in arithmetic plus the $RANDOM
var
> to get a random
> joke number:
>
> (( JOKE = ($RANDOM % $NLINES) + 1 ))
>
> 3) select joke number $JOKE to send. You could use
> perl or awk to do
> this. Of course you could probably use perl or awk to
> do all of this,
> but the object was using bash. With enough masochism,
> one could use
> bash to even select the joke, but it'll be rather
ugly!
>
How about this, or am I on the wrong track?
cut -d'=*' -f$RANDOM
Andrew
> --
> kernel, n.: A part of an operating system that
> preserves the
> medieval traditions of sorcery and black art.
>
> Danny
>
>
> ---
> This message has been sent through the ALE general
> discussion list.
> See <a
href="http://mail.directvinternet.com//jump/http://www.ale.org/mailing-lists.shtml">http://www.ale.org/mailing-lists.shtml</a> for more
> info. Problems should be
> sent to listmaster at ale dot org.
Andrew Grimmke
Marietta, Georgia
---
This message has been sent through the ALE general discussion list.
See http://www.ale.org/mailing-lists.shtml for more info. Problems should be
sent to listmaster at ale dot org.
More information about the Ale
mailing list