Re:The Beauty of Unix Pipelines (2020)
by kmstout on Sunday June 05, 2022 @12:23AM
(#31628000)
Roll your own:
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.
[ Parent
| on HN ]
To improve performance, consider using `export LC_ALL=C` (credit: https://benhoyt.com/writings/count-words/). But note that it sorts uppercase and lowercase separately, and doesn't handle Unicode well.
Someone 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