Skip to content

Instantly share code, notes, and snippets.

@roblogic
Last active October 26, 2017 05:49
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 roblogic/ddc5377d9db48f0f9ca2635a5d900c2c to your computer and use it in GitHub Desktop.
Save roblogic/ddc5377d9db48f0f9ca2635a5d900c2c to your computer and use it in GitHub Desktop.
Print basic statistics for numeric data input to stdin
#!/bin/sh
# thanks to http://unix.stackexchange.com/a/13779/62529
sort -n | awk '
BEGIN {
c = 0;
sum = 0;
}
$1 ~ /^[0-9]*(\.[0-9]*)?$/ {
a[c++] = $1;
sum += $1;
}
END {
ave = sum / c;
if( (c % 2) == 1 ) {
median = a[ int(c/2) ];
} else {
median = ( a[c/2] + a[c/2-1] ) / 2;
}
OFS="\t";
print sum, c, ave, median, a[0], a[c-1];
}
'
echo -e "sum\tn\tmean\tmedian\tmin\tmax"
@roblogic
Copy link
Author

roblogic commented Mar 29, 2017

Example

Analysing results from Jmeter's "Simple Data Writer"...

$ awk -F, '{print $2}' FPE1_50K_60tpm.csv | stats.sh
1195856 57604   20.7599 19      13      2710
sum     n       mean    median  min     max

@roblogic
Copy link
Author

Superseded by istats

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment