Skip to content

Instantly share code, notes, and snippets.

@jomat
Last active September 28, 2015 18:57
Show Gist options
  • Save jomat/1481810 to your computer and use it in GitHub Desktop.
Save jomat/1481810 to your computer and use it in GitHub Desktop.
Gelduebergabelogsummarizer
#!/bin/zsh
# save a | separated list in the TABLE_FILE
# i. e:
# | 02dec2011 21:23 | 5 | matemat | jomat |
# | 02dec2011 21:42 | 20 | matetjunkie | jomat | Direktverkauf 20 Stueck 1-Euro-Mate |
# | 05dec2011 20:23 | 46.6 | matemat | jomat |
# and run me
TABLE_FILE=/tmp/kohlen
typeset -A a
# initialize the array with name-keys
cat $TABLE_FILE|cut -f5 -d\||tr -d \ |sort|uniq|while read v;do a[$v]=0;done
cat $TABLE_FILE|cut -f4 -d\||tr -d \ |sort|uniq|while read v;do a[$v]=0;done
cat $TABLE_FILE|while read LINE;do
AMOUNT=`echo $LINE|cut -f3 -d\||tr -d \ `
FROM=`echo $LINE|cut -f4 -d\||tr -d \ `
TO=`echo $LINE|cut -f5 -d\||tr -d \ `
# echo transfering $AMOUNT gold: $FROM -\> $TO
a[$FROM]=`echo $a[$FROM]-\($AMOUNT\)|bc`
a[$TO]=`echo $a[$TO]+\($AMOUNT\)|bc`
done
for i in ${(k)a}
do
print $i: $a[$i]
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment