Skip to content

Instantly share code, notes, and snippets.

@romank0
Last active April 25, 2017 10:32
Show Gist options
  • Save romank0/13d4b951a69be048af10481d476bd6f5 to your computer and use it in GitHub Desktop.
Save romank0/13d4b951a69be048af10481d476bd6f5 to your computer and use it in GitHub Desktop.
#!/bin/bash
# stdin should be integers, one per line.
# command line perncentiles e.g. 75 90 95
percentiles=$*
tmp="$(mktemp -t percentileXXXX)"
total=$(sort -n | tee "$tmp" | wc -l)
for percentile in $percentiles
do
count=$(((total * percentile + 99) / 100))
echo "$percentile: $(head -n $count "$tmp" | tail -n 1)"
done
rm "$tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment