Sort and Clean

Device

  • Terminal

How

  1. Pipe output to sort to alphabetize lines.
  2. Use sort -u to sort and remove all duplicate lines globally.
  3. The uniq command only removes adjacent duplicate runs; sort the input first, or use sort -u instead.
  4. Example: printf 'apple\npear\napple\n' | uniq keeps both apples; ... | sort -u keeps one.

Try this

Run printf 'apple\npear\napple\n' | uniq, then the same list piped to sort -u. Notice uniq alone does not collapse non-adjacent duplicates.

Why it works

Make messy lists usable.

Open full demonstration ↗