LinuxCommandLibrary

cut

TLDR

Extract fields

$ cut -f [1,3] [file.txt]
copy
Extract columns by character
$ cut -c [1-10] [file.txt]
copy
Custom delimiter
$ cut -d [:] -f [1,7] [/etc/passwd]
copy
Extract bytes
$ cut -b [1-5] [file.txt]
copy

SYNOPSIS

cut [options] [file...]

DESCRIPTION

cut removes sections from each line of files. It extracts columns by character position, byte position, or field delimiter, making it useful for processing structured text data.
The command is commonly used in shell scripts for parsing columnar data.

PARAMETERS

-f, --fields list

Select fields (delimiter-separated)
-c, --characters list
Select characters
-b, --bytes list
Select bytes
-d, --delimiter char
Field delimiter (default: TAB)
--output-delimiter string
Output delimiter
-s, --only-delimited
Don't print lines without delimiter
--complement
Complement the selection

RANGE SPECIFICATION

- N - Nth item
- N- - From Nth to end
- N-M - From Nth to Mth
- -M - From beginning to Mth
- N,M - Nth and Mth

WORKFLOW

$ # Extract first field (default TAB delimiter)
cut -f 1 data.tsv

# Extract multiple fields
cut -f 1,3,5 data.tsv

# CSV with custom delimiter
cut -d ',' -f 2 data.csv

# Extract username from /etc/passwd
cut -d ':' -f 1 /etc/passwd

# Extract characters 1-10
cut -c 1-10 file.txt

# Extract first 20 bytes
cut -b 1-20 file.txt

# Change output delimiter
cut -d ',' -f 1,2 --output-delimiter=':' data.csv
copy

COMMON USES

Parse CSV:

$ cut -d ',' -f 2,4 data.csv
copy
Extract columns from ps:
$ ps aux | cut -c 1-20,50-70
copy
Get usernames:
$ cut -d ':' -f 1 /etc/passwd
copy
Field range:
$ cut -f 2-5 data.tsv
copy

CAVEATS

Cannot handle varying amounts of whitespace (use awk instead). Delimiter must be single character. Cannot reorder fields (use awk). No regular expression support. Quote handling in CSV requires other tools. Only operates on bytes/characters/fields, not by column width.

HISTORY

cut has been part of Unix since the early 1980s, part of System III and later POSIX standards.

SEE ALSO

paste(1), awk(1), tr(1), column(1)

Copied to clipboard