Last active
June 2, 2024 16:36
-
-
Save tralce/8ae4235cf507cc4b882b48522212ef22 to your computer and use it in GitHub Desktop.
WtU Raffle Script
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| workingfile="$(mktemp)" | |
| shuffledfile="$(mktemp)" | |
| winners="$(mktemp)" | |
| [ -z $1 ] && echo "Need a number of winners, yo." && exit 1 | |
| while read line | |
| do | |
| line=$(echo $line | tr -cd '[:alnum:] [:space:]') | |
| entry=1 | |
| count=$(echo $line|awk '{print $2}') | |
| ticket="$(echo $line|awk '{print $1}')" | |
| while [[ $entry -le $count ]] | |
| do | |
| echo "$ticket" >> $workingfile | |
| let ++entry | |
| done | |
| done | |
| totalentries="$(wc -l $workingfile|awk '{print $1}')" | |
| echo -e "\033[36m$totalentries total entries\n\033[0m" | |
| shuf $workingfile | sed '/^$/d' > $shuffledfile | |
| while [ "$(wc -l $winners|sed "s/ .*//")" -lt "$1" ] | |
| do | |
| winningticket=$(awk "FNR==$(shuf -i 1-$totalentries -n1) {print \$0}" $shuffledfile) | |
| grep $winningticket $winners &> /dev/null || echo $winningticket >> $winners | |
| done | |
| shuf $winners | |
| rm $workingfile | |
| rm $shuffledfile | |
| rm $winners |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment