bin/props @ 09b49bc1fd02

Update Vlime
author Steve Losh <steve@stevelosh.com>
date Thu, 23 Jan 2020 23:36:10 -0500
parents a81cac75b4d3
children d9ee2c4aa85b
#!/usr/bin/env bash

set -euo pipefail

OPTS=$(getopt --options hd:pP --long help,decimals:,percent,no-percent -n "$0" -- "$@")
eval set -- "$OPTS"

DECIMALS='5'
MUL='1.0'

while true; do
  case "$1" in
    -h | --help )
        echo "USAGE: $0 [-h|--help] [-n N | --decimals N] [--percent | --no-percent]"
        exit 0 ;;
    -d | --decimals )   DECIMALS="$2"; shift 2 ;;
    -p | --percent )    MUL='100.0';   shift ;;
    -P | --no-percent ) MUL='1.0';     shift ;;
    -- ) shift; break ;;
    * ) break ;;
  esac
done

awk '
    { c[$0]++ }
END { for (l in c) printf("%.'"$DECIMALS"'f %s\n", c[l] / NR * '"$MUL"', l) }
'