Skip to content

Instantly share code, notes, and snippets.

@skyscribe
Created March 1, 2012 02:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skyscribe/1946891 to your computer and use it in GitHub Desktop.
Save skyscribe/1946891 to your computer and use it in GitHub Desktop.
aggregate records by awk - calculate average per 5 minutes
cat $repFile | cut -d "|" -f2-5 | egrep "[0-9]\|$" | grep -v "None" | sort | gawk '
function getAdjustedTime(startTime)
{
split(startTime, splits, ":");
return sprintf("%s:%02d", splits[1], (int(splits[2]/5) * 5))
}
BEGIN{
FS="|";
printf("%20s | %6s | %6s | %3s | %3s\n", "TIME", "COUNT", "DUR", "AVG", "MAX")
printf("-------------------------------------------------------------\n")
}
{
time=getAdjustedTime($2)
stats[time]++;
durs[time] += $3
cnt++;
if (max[time] < $3){
max[time] = $3;
}
}
END{
printf "total=%d\n", cnt
for (tm in stats)
{
printf("%20s | %6d | %6d | %2.1f | %3d\n", tm, stats[tm], durs[tm], durs[tm]/stats[tm], max[tm])
}
}' | sort > $outFile
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment