Sortiq - sort, uniq, sort

less than 1 minute read

This is a small snippet I find extremely useful. You should have it in your ~/.bashrc:

sortiq() { sort | uniq -c | sort -rn ; }

It will count the instances of each line, sorting them from most common to least common.

What is this for

It answers the question “How much of each line do I have?” e.g. for this input:

badger
badger
badger
badger
mushroom
mushroom
badger
badger
badger
badger
mushroom
mushroom
snake
snake
snake
snake

Piping it via sortiq (like echo "$GOOD_INPUT" | sortiq) will give you:

      8 badger
      4 snake
      4 mushroom

Very handy.