Skip to content

Instantly share code, notes, and snippets.

@tralce
Last active October 27, 2022 00:16
Show Gist options
  • Save tralce/8ae4235cf507cc4b882b48522212ef22 to your computer and use it in GitHub Desktop.
Save tralce/8ae4235cf507cc4b882b48522212ef22 to your computer and use it in GitHub Desktop.
WtU Raffle Script
#!/bin/bash
workingfile="$(mktemp)"
shuffledfile="$(mktemp)"
winners="$(mktemp)"
[ -z $1 ] && echo "Need a number of winners, yo." && exit 1
while read line
do
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