Where to start First steps track · 15 stages
Linux Labs

sort, uniq, cut, wc, tr — text stream processing

cheat sheet · GNU coreutils https://lab.dimsanych.ru/en/wiki/text-tools/

Cheat sheet

  • sort -u file sort + unique
  • sort file | uniq -c | sort -rn line frequency (top)
  • cut -d: -f1 file a column by delimiter
  • tr 'a-z' 'A-Z' < file case conversion
  • column -t -s, file.csv align into a table
  • comm -12 <(sort a) <(sort b) the intersection of two files

Options

sort without -n compares lines as text: 10 sorts before 9, because the character "1" is less than "9" — numeric order needs -n. uniq only collapses lines that are identical and adjacent, so it almost always needs a sort first. cut splits fields on a tab by default — for CSV or passwd you set the delimiter explicitly with -d.

Loading…