Skip to content

Instantly share code, notes, and snippets.

@kid1412621
Created October 17, 2022 07:27
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 kid1412621/a75456fcf67ed683a7018ae000f8d264 to your computer and use it in GitHub Desktop.
Save kid1412621/a75456fcf67ed683a7018ae000f8d264 to your computer and use it in GitHub Desktop.
#!/bin/bash
percentile=90
input="put your line based number file"
tmp="tmpfile"
total=$(cat "$input" | sort -n | tee "$tmp" | wc -l)
echo "min: $(head -n 1 "$tmp" | tail -n 1)"
echo "max: $(tail -n 1 "$tmp" | tail -n 1)"
# (n + 99) / 100 with integers is effectively ceil(n/100) with floats
percentile_rank=$(((total * percentile + 99) / 100))
percentile_score=$(head -n $percentile_rank "$tmp" | tail -n 1)
echo "p$percentile: $percentile_score"
sum=$(paste -sd+ "$tmp" | bc)
echo "avg: $(($sum/$total))"
rm "$tmp"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment