[kwlug-help] (Lottery) bash (?) programming - array, inlist, ???

Chris Frey cdfrey at foursquare.net
Thu Jun 24 20:52:34 EDT 2010


On Sun, Jun 20, 2010 at 02:42:39PM -0400, unsolicited wrote:
> Assuming arguments of a filename list of ticket numbers and a filename 
> list of draws ...
> 
> for each line in draw
> {
>   for each line in ticket
>   {
>    if( #1 inlist(draw) + #2 inlist(draw) + ... #7 inlist(draw) > 2 ) 
> echo Winner, ticket X, draw Y.
>    # Assuming true = 1, then the sum of the logical functions = a 
> count. And > 2 means at least a free ticket.
>   }
> }

I'm not sure I understand the full data flow here, but if you just want
to find one piece of data in another file, use grep.

If you need the count, you can use the -c option.  For example:

	(echo hi ; echo hi) | grep -c h

... will output 2.

You can include this in your calculations using $( ... grep -c h ), etc.

Is this close to what you were hoping for?

- Chris




More information about the kwlug-help mailing list