ZetCode

Linux cut Command

last modified October 23, 2026

The cut command in Linux extracts sections from each line of its input. It can select characters or bytes by position, or fields separated by a delimiter, such as columns of a CSV file or of /etc/passwd. The result is written to standard output; the input files are not modified.

cut is a simple and fast filter, often combined with sort, uniq, tr, and wc in pipelines. The examples use GNU cut from coreutils.

Selecting characters

The -c option selects characters by their position, starting from 1.

cut -c 1-3 words.txt
cut -c 2,4 words.txt
cut -c 4- words.txt

A list can contain single positions, ranges such as 1-3, and open ranges: 4- means from the fourth character to the end of the line, and -3 means from the first to the third. Selected characters are always output in their original order. The line sky has no fourth character, so an empty line is printed for it.

$ cut -c 1-3 words.txt
sky
for
fal
clo
ten
$ cut -c 2,4 words.txt
k
oe
ac
lu
es
$ cut -c 4- words.txt

est
con
ud
sion

Selecting fields

The -d option sets the field delimiter, and -f selects fields.

cut -d, -f2 employees.csv
cut -d, -f2,4 employees.csv
cut -d, -f2- employees.csv

The fields of the CSV file are separated by commas. Field lists accept the same syntax as character lists. The delimiter must be a single character; the default is the tab. Note that cut does not understand quoting, so it cannot handle CSV values that contain commas.

$ cut -d, -f2 employees.csv
name
Paul
Lucy
John
Anna
$ cut -d, -f2,4 employees.csv
name,salary
Paul,2400
Lucy,980
John,3100
Anna,1850
$ cut -d, -f2- employees.csv
name,city,salary
Paul,London,2400
Lucy,Paris,980
John,Berlin,3100
Anna,London,1850

Changing the output delimiter

By default, the selected fields are joined with the input delimiter. The --output-delimiter option sets a different string.

cut -d: -f1,7 users.txt
cut -d: -f1,6 --output-delimiter=" -> " users.txt

The file has the format of /etc/passwd. The first command prints the user names and their login shells; the second prints the user names and home directories separated by an arrow. On a real system, the same commands work on /etc/passwd directly.

$ cut -d: -f1,7 users.txt
root:/bin/bash
daemon:/usr/sbin/nologin
jano:/bin/bash
alice:/bin/zsh
$ cut -d: -f1,6 --output-delimiter=" -> " users.txt
root -> /root
daemon -> /usr/sbin
jano -> /home/jano
alice -> /home/alice

Inverting the selection

The --complement option outputs everything except the selected fields or characters.

cut -d, -f1,4 --complement employees.csv

The ID and salary columns are removed, which is easier than listing all the columns to keep.

$ cut -d, -f1,4 --complement employees.csv
name,city
Paul,London
Lucy,Paris
John,Berlin
Anna,London

Skipping lines without delimiters

Lines that do not contain the delimiter are printed unchanged. The -s option suppresses them.

cut -d: -f1,2 servers.txt
cut -d: -f1,2 -s servers.txt

The comment line has no colon, so the first command prints it as it is. With -s, only lines with fields are printed, which conveniently drops comments and headers without delimiters.

$ cut -d: -f1,2 servers.txt
# server list
web01:10.0.0.11
web02:10.0.0.12
db01:10.0.0.21
$ cut -d: -f1,2 -s servers.txt
web01:10.0.0.11
web02:10.0.0.12
db01:10.0.0.21

Fields separated by multiple spaces

cut treats every delimiter character as a field separator, so repeated spaces create empty fields. This is a problem with the aligned output of many commands.

cut -d" " -f2 report.txt
tr -s " " < report.txt | cut -d" " -f2

The first command prints empty lines, because the second field is the empty string between the first two spaces. Squeezing repeated spaces with tr -s fixes the problem. Alternatively, awk '{print $2}' splits on runs of whitespace by default.

$ cat report.txt
Paul  London   2400
Lucy  Paris     980
$ cut -d" " -f2 report.txt


$ tr -s " " < report.txt | cut -d" " -f2
London
Paris

Characters and bytes

The -b option selects bytes. GNU cut currently treats -c the same as -b, so it does not handle multibyte UTF-8 characters correctly.

echo "číslo" | cut -c 1-3
echo "číslo" | cut -b 1-3

The letters č and í take two bytes each in UTF-8. Both commands select the first three bytes, which splits the second letter and produces an invalid character. For text with non-ASCII characters, use tools that are aware of the encoding, such as GNU awk (gawk) in a UTF-8 locale or a scripting language.

$ echo "číslo" | cut -c 1-3
č�
$ echo "číslo" | cut -b 1-3
č�

cut in pipelines

cut is typically one step in a pipeline.

tail -n +2 employees.csv | cut -d, -f3 | sort | uniq -c
echo "$PATH" | cut -d: -f1

The first pipeline skips the header, extracts the cities, and counts the employees per city. The second prints the first directory of the PATH variable.

$ tail -n +2 employees.csv | cut -d, -f3 | sort | uniq -c
      1 Berlin
      2 London
      1 Paris
$ echo "$PATH" | cut -d: -f1
/usr/local/bin

Best practices for cut

Source

GNU cut manual

In this article, we have used the cut command to extract characters and fields from lines, change the output delimiter, invert selections, and combine cut with other commands.

Author

My name is Jan Bodnar, and I am a passionate programmer with extensive programming experience. I have been writing programming articles since 2007. To date, I have authored over 1,400 articles and 8 e-books. I possess more than ten years of experience in teaching programming.

List all Linux tutorials.