Created
October 17, 2022 07:27
-
-
Save kid1412621/a75456fcf67ed683a7018ae000f8d264 to your computer and use it in GitHub Desktop.
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/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