Terminal · foundation

Selecting fields with cut

cut selects byte, character, or delimiter-separated field positions from each input line without parsing quoting or nested record formats.

Why it matters

It is an efficient tool for simple, regular text layouts, provided the delimiter is one character and the data does not require CSV-aware parsing.

Mental model

How to reason about selecting fields with cut

Process each line independently, split it on the exact delimiter when in field mode, and emit only the requested numbered pieces in input order.

Analogy

It resembles taking the same numbered vertical slices from every row of a paper table, without understanding what the cell contents mean.

Examples

See the boundary, not just the happy path

Worked example · Read login names

cut -d: -f1 /etc/passwd

Each line is split at colon characters and field 1 is emitted; this works because the file's format reserves colon as a delimiter.

Worked example · Select a range of fields

printf '%s\n' 'eu,api,healthy' | cut -d, -f1,3

cut emits the first and third comma-delimited fields, producing eu,healthy with the input delimiter between selected fields.

Avoid · Quoted CSV

printf '%s\n' '"Doe, Ada",admin' | cut -d, -f1

cut does not understand CSV quoting, so the comma inside the quoted value is still treated as a delimiter.

Common mistakes

Misconceptions to remove early

Using cut for whitespace-separated columns

Repeated or mixed whitespace does not form one stable single-character delimiter; awk's field model is often a better fit.

Assuming field mode parses CSV

CSV supports quoting, escaped quotes, and embedded delimiters or newlines that require a format-aware parser.

Quick check

Can you predict the result?

1. What does -d: -f2 ask cut to emit?
  • The second colon-delimited field from each input line
  • Everything after the second colon
  • The second character
Answer: The second colon-delimited field from each input line
2. Why is cut unreliable for general CSV?
Answer: It splits on delimiter characters without understanding CSV quoting or embedded delimiters.

Keep building

Authoritative references

Make the idea retrievable.

Study this concept with spaced repetition, next to the commands where you use it.

Get Terminaster