Skip to content

Instantly share code, notes, and snippets.

@jesboat
Last active August 29, 2015 13:57
Show Gist options
  • Save jesboat/9437645 to your computer and use it in GitHub Desktop.
Save jesboat/9437645 to your computer and use it in GitHub Desktop.
Simple histogram
hist() {
local sortopts1= sortopts2=
while [[ $# != 0 && "$1" == -* ]]; do
if [ "$1" = -r ]; then
sortopts2=-r
elif [ "$1" = -n ]; then
sortopts1=-n
elif [[ "$1" = -rn || "$1" = -nr ]]; then
sortopts1=-n sortopts2=-r
else
echo "Usage: hist [-nr] [infile ...]" >&2
return 1
fi
shift
done
if [ $# = 0 ]; then
sort $sortopts1 | uniq -c | sort -n $sortopts2
return $?
else
cat "$@" | sort $sortopts1 | uniq -c | sort -n $sortopts2
return $?
fi
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment