A book about the command line for humans.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

30 lines
580 B

#!/usr/bin/env bash
# Optionally specify number of lines to show, defaulting to 10:
TOSHOW=10
CASEOPT=""
while getopts ":in:" opt; do
case $opt in
i)
CASEOPT="-i"
;;
n)
TOSHOW=$OPTARG
;;
\?)
echo "Invalid option: -$OPTARG" >&2
exit 1
;;
:)
echo "Option -$OPTARG requires an argument." >&2
exit 1
;;
esac
done
# sort and then uniqify STDIN,
# sort numerically on the first field,
# chop off everything but $TOSHOW lines of input
sort < /dev/stdin | uniq -c $CASEOPT | sort -k1 -nr | head -$TOSHOW