Skip to content

Instantly share code, notes, and snippets.

@kozross
Created May 19, 2016 00:03
Show Gist options
  • Save kozross/6b6d60e9da6b9db24cfa68b3035ba4df to your computer and use it in GitHub Desktop.
Save kozross/6b6d60e9da6b9db24cfa68b3035ba4df to your computer and use it in GitHub Desktop.
#!/usr/bin/gawk -f
BEGIN {
# set up tracker for which epoch we're in
epoch = -1
# set up counter for how many entries we've seen
counter = 0
# set up accumulators
total_breath_length = 0
total_inspiration_length = 0
}
# first row
NR == 1 {
first_epoch = $5
epoch = $5
counter = 1
total_breath_length = $3
total_inspiration_length = $4
}
# same epoch
$5 == epoch {
counter = counter + 1
total_breath_length = total_breath_length + $3
total_inspiration_lenth = total_inspiration_length + $4
}
# different epoch
{
aggregates[epoch, "total"] = total_breath_length / counter
aggregates[epoch, "inspiration"] = total_inspiration_length / counter
epoch = $5
counter = 1
total_breath_length = $3
total_inspiration_length = $4
}
END {
PROCINFO["sorted_in"] = "@ind_num_asc"
for (e in aggregates) {
printf("%d %f %f\n", e, aggregates[e, "total"], aggregates[e, "inspiration"])
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment