News for hackers. Stuff that matters.
Re:The Beauty of Unix Pipelines (2020) by kmstout on Sunday June 05, 2022 @12:23AM (#31628000)
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.
Re:The Beauty of Unix Pipelines (2020) by hddqsb on Sunday June 05, 2022 @02:23AM (#31628510)
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.
Re:The Beauty of Unix Pipelines (2020) by kmstout on Sunday June 05, 2022 @12:43AM (#31628082)
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