Skip to content

Instantly share code, notes, and snippets.

@hkoba
Created October 27, 2014 14:57
Show Gist options
  • Save hkoba/5fdbaa0dfe1e9a95516e to your computer and use it in GitHub Desktop.
Save hkoba/5fdbaa0dfe1e9a95516e to your computer and use it in GitHub Desktop.
How to use associative array to calculate summary in Zsh
#!/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