a81cac75b4d3

freqs and props
[view raw] [browse files]
author Steve Losh <steve@stevelosh.com>
date Thu, 23 Jan 2020 23:35:07 -0500
parents 39c693929f1b
children a362de5d1aa1
branches/tags (none)
files bin/freqs bin/props

Changes

--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/freqs	Thu Jan 23 23:35:07 2020 -0500
@@ -0,0 +1,5 @@
+#!/usr/bin/env bash
+
+set -euo pipefail
+
+awk '{ c[$0]++ } END { for (l in c) print c[l], l }'
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/bin/props	Thu Jan 23 23:35:07 2020 -0500
@@ -0,0 +1,27 @@
+#!/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) }
+'