Created
August 13, 2014 13:59
-
-
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)
This file contains 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
#! /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