Skip to main content

cut Cheatsheet

By Dejan Panovski Updated on Download PDF

Quick reference for extracting fields, bytes, and characters with cut in Linux

The cut command extracts sections from each line of files or standard input. This cheatsheet covers field, byte, and character selection, custom delimiters, and common pipeline usage.

Select Fields

Pick columns with -f (default delimiter is TAB).

CommandDescription
cut -f1 file.txtSelect the first field
cut -f1,3 file.txtSelect fields 1 and 3
cut -f1-4 file.txtSelect fields 1 through 4
cut -f2- file.txtFrom field 2 to the end of the line
cut -f-3 file.txtFrom the first field through field 3

Delimiters

Set the input delimiter and control output.

CommandDescription
cut -d',' -f1 file.csvUse a comma as the delimiter
cut -d':' -f1,3 fileColon delimiter, fields 1 and 3
cut -d' ' -f2 fileSpace delimiter, second field
cut -s -d',' -f1 fileSkip lines with no delimiter
cut --output-delimiter='_' -f1,3 fileSet a different output delimiter

Bytes and Characters

Cut by position instead of field.

CommandDescription
cut -c1-10 fileFirst 10 characters of each line
cut -c3- fileFrom character 3 to the end
cut -c1,4,7 fileCharacters at positions 1, 4, and 7
cut -b1-5 fileFirst 5 bytes of each line
cut -b5,9,13 fileBytes at positions 5, 9, and 13

Invert and Combine

Exclude a selection or chain with other tools.

CommandDescription
cut -f1,3 --complement filePrint every field except 1 and 3
cut -c1-5 --complement filePrint every character except 1 to 5
cut -d':' -f1,7 /etc/passwdUsernames and login shells
echo "$PATH" | cut -d':' -f1First entry in the PATH variable
cut -d',' -f2 data.csvExtract the second CSV column

Common Pipelines

Practical combinations with other commands.

CommandDescription
getent passwd | cut -d':' -f1List all system users
grep "^$USER:" /etc/passwd | cut -d':' -f7Default shell for the current user
echo "one two three" | tr -s ' ' | cut -d' ' -f2Collapse repeated spaces, then cut
ls -l file.txt | cut -c1-10Permission string for one file
who | cut -d' ' -f1 | sort -uUnique logged-in users

Troubleshooting

Quick checks for common cut issues.

IssueCheck
Whole line printed unchangedWrong delimiter; the default is TAB, set -d to match the input
Lines without a delimiter still showAdd -s to skip lines containing no delimiter
Cannot use -f, -b, -c togetherUse only one selection mode per command
Multibyte characters look garbledUse -c to cut by character, not -b (bytes)
Repeated spaces split oddlycut treats each delimiter literally; normalize with tr -s or use awk

Use these guides for full text-processing workflows.

GuideDescription
cut Command in LinuxFull cut guide with examples
awk Command in LinuxPattern-based field extraction
tr Command in LinuxTranslate and squeeze characters
sort Command in LinuxOrder lines from files or input
grep Command in LinuxSearch and filter matching lines