Created
February 4, 2015 00:03
-
-
Save philcryer/eae52026e4bc1a4237dd to your computer and use it in GitHub Desktop.
voting results
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 | |
| # tally the votes each canidate recieved in the election | |
| in=/tmp/2012_GENERAL.txt | |
| out=/tmp/2012_GENERAL-results.txt | |
| if [ ! -f "${in}" ]; then | |
| echo -n "> Downloading file..." | |
| curl -s http://www.analyzethevote.com/download/2012_GENERAL.txt -o $in | |
| echo "done" | |
| fi | |
| if [ -f "${out}" ]; then | |
| rm ${out} | |
| fi | |
| echo -n "> Calculating results..." | |
| declare -a functions=( BARACK GARY JILL MITT Write ) | |
| for f in ${functions[@]}; do | |
| eval "$f() { | |
| echo -n " -- $f...." >> $out | |
| echo `cat $in|grep $f|awk '{print substr($0, length($0)-4)}'|awk '{x+=$0}END{print x}'` >> $out | |
| }" | |
| $f | |
| done | |
| echo "done" | |
| cat $out|sed -i -e 's/Write/Write\ In/g' $out | |
| echo "> Presenting results..." | |
| cat $out | |
| echo -n "> Cleaning up..." | |
| rm $in $out | |
| echo "done" | |
| exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment