Created
October 27, 2014 14:57
-
-
Save hkoba/5fdbaa0dfe1e9a95516e to your computer and use it in GitHub Desktop.
How to use associative array to calculate summary in Zsh
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/zsh | |
# Rewrite of http://www.atmarkit.co.jp/ait/articles/1208/17/news110_2.html | |
# unset summary; | |
typeset -A summary; | |
while read prod amt; do | |
((summary[$prod]+=$amt)) | |
done | |
for prod in ${(ko)summary}; do | |
echo $prod $(date +%Y-%M-%d) $summary[$prod] | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment