Bash Lotto Lookup

My dad likes to play the NJ Lottery. He usually buys Mega Million tickets, and then forgets to check if he won anything. So every once in a while, he asks me to look up the numbers for a certain date. After doing this couple of times for him, I ended up hacking this simple bash script to automate the process:

#!/bin/bash
if [ "$1" = "" ]; then echo "usage lotto [ mm/dd/yyyy ]" ; exit; fi
lynx -dump "http://www.state.nj.us/lottery/games/1-1-3_mega_history.shtml" | grep "$1"

Note that since I’m using grep, I can do all sorts of fancy regexp stuff when calling this script. For example:, to get all the drawings from Jan-May 2006 I can simply do:

lotto 12/../.*

will find all the results from December

lotto 0[1-5]/../...6

will find all the results from the Jan-May 2006 period

Note that I can also use this for searching other fields – not just the date. For example, if I want to see all the winning number combinations that are archived on the page I can simply do:

lotto ,0

Alternatively I can do:

lotto [^0]0.00$

to see all the numbers that did not win. And of course, I can just search directly for the number sequence to see if a given number won.

I don’t know how useful is this to anyone, but I figured that I might as well put it out there, since I have been using it for a while now.

[tags]NJ lottery, mega million, lottery, bash, linux, lynx, regexp[/tags]

This entry was posted in Uncategorized. Bookmark the permalink.



Leave a Reply

Your email address will not be published. Required fields are marked *