bin/freqs @ 785a46b1b198

More
author Steve Losh <steve@stevelosh.com>
date Thu, 05 Nov 2020 10:33:03 -0500
parents d9ee2c4aa85b
children (none)
#!/usr/bin/env bash

set -euo pipefail

function usage {
    echo "freqs - display frequencies of the unique lines of stdin

USAGE: $0 [OPTIONS]

Options:
  -h, --help    display this help text and exit
"
}

function die {
    echo "$0: $1" >&2;
    exit 1
}

OPTS=$(getopt --options h --long help --name "$0" -- "$@")
eval set -- "$OPTS"

while test "$#" -gt 0; do
    case "$1" in
        -h | --help ) usage; exit 0;;
        -- ) shift; if test "$#" -ne 0; then die "unrecognized arguments: $*"; fi ;;
        * ) die "unrecognized arguments: $*" ;;
    esac
done

awk '{ c[$0]++ } END { for (l in c) print c[l], l }'