sort and remove duplicate lines

Sort lines, keep each once, count how often each appears.

  • text

Steps

  1. sort file.txt

    sort the lines

  2. sort -u file.txt

    sort them and keep each once

  3. sort file.txt | uniq -c | sort -rn

    how often each line appears, most first

  4. awk '!seen[$0]++' file.txt

    keep each once, in their order

  5. sort -t, -k3 -n data.csv

    sort a CSV by its third column, as numbers

  6. sort -h sizes.txt

    sort sizes like 2K, 1M, 3G

Notes

  • uniq only removes repeats next to each other: sort first.

Commands used

  • sort
  • uniq
  • awk

Each has a page in lore: lore sort opens it.