Interview Prep/Shell Scripting/Text processing: grep, sed, awk, cut, sort, uniq

What does `cut` do, and when do you prefer `awk` instead?

BeginnerConceptText processing: grep, sed, awk, cut, sort, uniq
Answer

cut extracts fields by a single-character delimiter (-d, -f) or by character positions (-c).

cut -d: -f1,7 /etc/passwd
cut -d, -f2- users.csv      # field 2 to the end
cut -c1-19 app.log          # timestamp prefix

cut treats every delimiter as a field boundary, so runs of spaces (like ps or df output) produce empty fields. awk splits on runs of whitespace by default, so for whitespace-aligned output use awk '{print $2}'.

All Shell Scripting questions Roadmap: Shell scripting (Bash)

More on Text processing: grep, sed, awk, cut, sort, uniq