-
-
Save roblogic/139891f110d39bbd2500a699e3d8b060 to your computer and use it in GitHub Desktop.
Print percentiles for list of data points
This file contains hidden or 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
#!/bin/sh | |
# Exit immediately on error | |
set -e | |
# set -x | |
# Create temporary file | |
FILE=$(mktemp /tmp/$(basename $0).XXXXX) || exit 1 | |
# Sort entries | |
sort -n $* > $FILE | |
# Count number of data points | |
N=$(wc -l $FILE | awk '{print $1}') | |
echo "Percentiles at 50, 90, 95 and 99 % for $N data points:" | |
# Calculate line numbers for each percentile we're interested in | |
P50=$(dc -e "$N 2 / p") | |
P90=$(dc -e "$N 9 * 10 / p") | |
P95=$(dc -e "$N 95 * 100 / p") | |
P99=$(dc -e "$N 99 * 100 / p") | |
awk "FNR==$P50 || FNR==$P90 || FNR==$P95 || FNR==$P99" $FILE | |
echo "Std. dev:" | |
awk '{x+=$0;y+=$0^2}END{print sqrt(y/NR-(x/NR)^2)}' $FILE |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Super-superseded by istats