2 ms·
Roll your own: ~/bin/freq ========== #! /bin/bash sort "$@" | uniq -c | sort -nr Once you get into the habit of capturing your habits as scripts that
by kmstout 4y ago
Roll your own:
~/bin/freq
==========
#! /bin/bash
sort "$@" | uniq -c | sort -nr
Once you get into the habit of capturing your habits as scripts that snap together like German nouns, you'll find the command line a wondrous place.
- kmstout 4y agoSomeone else mentioned using a hash table to accumulate counts; that approach would give something like ~/bin/freq ========== #! /bin/bash awk '{acc[$0]++} END {for (item in acc) {print acc[item], item}}' | sort -nr
- hddqsb 4y agoTo improve performance, consider using `export LC_ALL=C` (credit: https://benhoyt.com/writings/count-words/ https://benhoyt.com/writings/count-words/). But note that it sorts uppercase and lowercase separately, and doesn't handle Unicode well.