Skip to content

Instantly share code, notes, and snippets.

@philcryer
Created February 4, 2015 00:03
Show Gist options
  • Select an option

  • Save philcryer/eae52026e4bc1a4237dd to your computer and use it in GitHub Desktop.

Select an option

Save philcryer/eae52026e4bc1a4237dd to your computer and use it in GitHub Desktop.
voting results
#!/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