Making the Cut: Slicing Up Text in the Linux CLI
Luke Hebert
- 2 minutes read - 237 wordsThe cut command is one of the fastest ways to pull specific columns out of a delimited text file without opening a spreadsheet or writing a script. If you are parsing log files, CSV exports, or the output of other commands, cut keeps things simple and fast.
Basic Syntax
cut -d DELIMITER -f FIELD_LIST INPUT_FILE-dsets the delimiter character (the character that separates fields).-fspecifies which field(s) to extract, starting at 1.- You can request multiple fields with a comma-separated list or a range (e.g.,
-f1,3-5).
Example: Extracting the 7th Field from a Colon-Delimited File
cut -d : -f7 /etc/passwdHere -d : tells cut that each field is separated by a colon, and -f7 grabs the seventh field (the user’s home directory in /etc/passwd).
Common Variations
# Print fields 1 through 3, tab-delimited
cut -f1-3 file.tsv
# Use a custom delimiter (pipe) and grab field 2
cut -d '|' -f2 data.txt
# Output to a new file instead of stdout
cut -d ',' -f4 input.csv -o output.txt
# Combine with other commands
ps aux | cut -d ' ' -f1,11Tips
- If you omit
-d,cutdefaults to a tab delimiter. - Field numbers are 1-based, not 0-based.
cutworks on any text stream, so piping it into or out of other commands is a natural fit.- For more complex parsing (quoting, escaped delimiters), consider
awkor a small Python one-liner instead.