Skip to content

Instantly share code, notes, and snippets.

@philippgeisler
Created August 13, 2014 13:59
Show Gist options
  • Save philippgeisler/4ce5bda5ad02786062bf to your computer and use it in GitHub Desktop.
Save philippgeisler/4ce5bda5ad02786062bf to your computer and use it in GitHub Desktop.
Simple Awk-script to calculate sums of values (here in $2) grouped by some field (here $1)
#! /usr/bin/awk -f
# equivalent oneliner for aliases: awk -F "|" '{group[$1] += $2} END{for (g in group) print group[g], "\t", g;}'
BEGIN {
FS="|"
}
{
group[$1] += $2
}
END {
for (g in group)
print group[g], "\t", g
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment