Shell script to check lotto ticket file for winners


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Shell script to check lotto ticket file for winners
# 1  
Old 06-25-2010
Shell script to check lotto ticket file for winners

OK, so I've got some time on my hands due to a workplace injury, but due to a couple of broken bones and the good drugs, actually implementing something useful is proving challenging Smilie

I am playing with generating large numbers of Pick 6 lottery ticket combos. These are stored in tab-delimited text files, 1 ticket per line. For my purposes I'm looking at large numbers of combos - 10,000 or greater per file.

Somehow I need to check these ticket combo files for winning numbers (either prompted for, or read from another file) - specifically, 2/6 + bonus, 3/6, 4/6, 5/6, 5/6 + bonus, and 6/6. I need the total number of each per file. Flagging which line number of each would be useful as well.

Years ago I had knocked together a Perl script to do this, but that was several hard drives ago, and I have no idea if it still exists somewhere, and I haven't looked at the problem since.

So, I was thinking a shell script using grep and/or awk might work, but I have no idea how to get either utility to count individual numbers per line and add them up.

I have cygwin installed on Windows 7, so presumably BASH and the standard utilities should work.

I did search around, but found nothing relevant.

Thanks for all help (code samples appreciated).
# 2  
Old 06-26-2010
assume you have file with winning numbers: Note-- I don't do lotto, my example may lack number of digits req'd.
win.txt
01 07 19 25 29 30
another file test.txt with 10000 lines like this
13 15 19 30 35 36

Code:
awk ' FILENAME=="win.txt" {
           for(i=1;i<=NF; i++) { win[$i]=1}
           
        }
        FILENAME=="test.txt" {
           tmp=0
           for(i=1; i<= NF; i++) { if($i in win){ tmp++} }
           if(tmp) {arr[$0]=tmp}
        }
        END {for ( i in arr) {print arr[i], i}} ' win.txt test.txt

This gets you started. You get to add the if's in the END function.
Login or Register to Ask a Question

Previous Thread | Next Thread

9 More Discussions You Might Find Interesting

1. UNIX for Beginners Questions & Answers

Shell Script to check a file

I'm required to write a simple shell script that when it runs it writes the output which is a simple barcode to a tmp flat file which I can do the bit I'm struggling with... The next time it runs I need to check the tmp output file to see if that barcode is in the output file and if it is send... (5 Replies)
Discussion started by: worky
5 Replies

2. Shell Programming and Scripting

To check whether the file is empty or not in shell script (sh)

Hi All, I need to check a file whether it exists and also whether it is empty or not. I have a code for this but it is not working as per my requirement. Can anyone pls suggest me on this. function funcFLSanityCheck { if then echo "${varFLSentFileListPath}/${varFLSentFileName}... (7 Replies)
Discussion started by: Arun1992
7 Replies

3. UNIX for Dummies Questions & Answers

Need shell script to check file

Hi Experts, I am not good in writing script. Just stared.I am looking for shell script to check following parameters. 1) Number of files on remote Linux SUSE server.- Any directory and sub directory. 2) I should define number of files in script. Files should be variable. 3) Age of... (2 Replies)
Discussion started by: ApmPerfMonitor
2 Replies

4. Shell Programming and Scripting

How to check the duplicancy of file using shell script?

Hi all, i am getting the file through sftp from a location in the name of 20141201_file.txt (iam getting the file on daily basis with date appended at the beginning) so before going to my actual process ,i want to check whether today files and yesterday file are same or not(which i used to... (3 Replies)
Discussion started by: hemanthsaikumar
3 Replies

5. Shell Programming and Scripting

Shell script to read file and check file type

Hi, I have a file with few values in it. I need script help to read file line by line and check: 1/if it's a file (with extension eg .java .css .jar etc ) or 2/if it's a file without extension and treat it as a directory and then check if the directory exists in working copy else create one... (6 Replies)
Discussion started by: iaav
6 Replies

6. Shell Programming and Scripting

How to check file name format using shell script?

Hi, I am writting a script, which accepts input file as parameter. Input file name is aa_bb_cc_dd_ee.<ext> I need to check that input file name should be of 5 fileds. Please help me out. :confused: (7 Replies)
Discussion started by: Poonamol
7 Replies

7. Shell Programming and Scripting

Need to check for empty file in C shell script

I am running a C shell script. I have an output file from a previous step and I need to run "something" in the next step to check if the file is empty. If the file is empty, then the job script should finish EOJ. If the file is not empty then the job script should abend. Please help Thanks. (4 Replies)
Discussion started by: jclanc8
4 Replies

8. Shell Programming and Scripting

need to check the file using ftp in a shell script

i need to write a shell script.. connecting to another server using ftp and check whether the file ter.txt is exists there or not. i have written scirpt partially,as i new to Unix. ftp -inv $FTPHOST > $TEMPFILE1 2> $TEMPFILE1 << EOF user $FTPUSER $FTPPW binary prompt ${CD} ls *.txt... (11 Replies)
Discussion started by: KiranKumarKarre
11 Replies

9. Shell Programming and Scripting

File System Check using shell script !!!

Hi Guys I m posing this new thread as I didnt get satisfactory result after running search here. My requirement is very simple (using shell script) I need to findout what all file systems are mounted -> Then I need check the health of that file system - by disk usage & by doing a simple... (8 Replies)
Discussion started by: csaha
8 Replies
Login or Register to Ask a Question