cut: Usage, Options & Common CI Errors
cut pulls out specific columns (fields, characters, or bytes) from each line.
cut is the lightweight column extractor. Its main limitation versus awk: the delimiter is a single character and runs of whitespace are not collapsed, which surprises people parsing spaced output.
What it does
cut selects portions of each input line by character range (-c), byte range (-b), or delimited field (-f with -d). It is fast and simple but does not handle multi-char or repeated delimiters.
Common usage
cut -d: -f1 /etc/passwd # first colon field
cut -d, -f2,4 data.csv # fields 2 and 4
cut -c1-8 file.txt # first 8 characters
echo "a:b:c" | cut -d: -f2- # field 2 to end
cut -d'\t' -f3 tsv.txt # tab-delimitedOptions
| Flag | What it does |
|---|---|
| -f <list> | Select fields (1, 2-4, 3-) |
| -d <char> | Field delimiter (single char, default TAB) |
| -c <list> | Select character positions |
| -b <list> | Select byte positions |
| --complement | Invert the selection (GNU) |
Common errors in CI
cut: the delimiter must be a single character - you cannot split on a string or a regex (use awk for that). cut does NOT collapse multiple spaces, so columns aligned with variable spacing come out wrong; use awk or tr -s ' ' first. Lines without the delimiter are passed through whole by default (-s suppresses them). --complement is GNU-only and missing on BSD/macOS cut.