🎁 New User? Get 20% off your first purchase with code NEWUSER20 Register Now →
Menu

Categories

cut Command

Beginner Text Processing man(1)

Remove sections from each line of files

👁 11 views 📅 Updated: Mar 15, 2026
SYNTAX
cut [OPTION]... [FILE]...

What Does cut Do?

The cut command extracts specific sections from each line of input — by character position, byte position, or delimited field number. It is one of the simplest and fastest text extraction tools in Linux.

cut is ideal for extracting columns from structured text like CSVs, TSVs, /etc/passwd, and command output. It works by specifying which characters, bytes, or fields to keep using the -c, -b, or -f flags.

While cut is simpler than awk, it has limitations: it only supports single-character delimiters and cannot reorder fields. For more complex extractions involving multi-character delimiters, conditions, or field reordering, use awk instead.

Options & Flags

OptionDescriptionExample
-d Set field delimiter (default: TAB) cut -d',' -f1,3 data.csv
-f Select fields by number cut -d':' -f1,7 /etc/passwd
-c Select characters by position cut -c1-10 file.txt
-b Select bytes by position cut -b1-20 file.txt
--complement Output everything except selected fields cut -d',' --complement -f2 data.csv
--output-delimiter Set output delimiter (can differ from input) cut -d':' -f1,7 --output-delimiter=' ' /etc/passwd

Practical Examples

#1 Extract username and shell from /etc/passwd

Shows username (field 1) and login shell (field 7) from the password file.
$ cut -d':' -f1,7 /etc/passwd
Output: root:/bin/bash www-data:/usr/sbin/nologin

#2 Extract CSV columns

Extracts the 2nd and 4th columns from a CSV file.
$ cut -d',' -f2,4 employees.csv

#3 Extract first 20 characters

Displays only the first 20 characters of each line.
$ cut -c1-20 longlines.txt

#4 Extract IP addresses from log

Extracts the first field (IP address) and shows unique values.
$ cut -d' ' -f1 access.log | sort -u

#5 Remove a specific column

Outputs all columns except the 3rd one.
$ cut -d',' --complement -f3 data.csv

#6 Change delimiter in output

Extracts fields with colon delimiter but outputs with tabs.
$ cut -d':' -f1,3,7 --output-delimiter=' ' /etc/passwd
Output: root 0 /bin/bash

Tips & Best Practices

Single-character delimiter only: cut only supports single-character delimiters. For multi-character delimiters or regex-based splitting, use awk instead.
Field ranges: Use ranges with -f: -f1-3 (fields 1 to 3), -f3- (field 3 onward), -f-5 (fields 1 to 5).
Spaces in CSV: If CSV fields contain the delimiter character, cut will split incorrectly. Use a proper CSV parser (awk or csvtool) for complex CSV files.

Frequently Asked Questions

How do I extract a column from a CSV?
Use cut -d',' -f2 file.csv to extract the 2nd column. For multiple columns: cut -d',' -f1,3,5 file.csv.
What is the difference between cut and awk for columns?
cut is simpler and faster for basic field extraction. awk is more powerful — it handles multi-character delimiters, conditions, calculations, and can reorder fields.
How do I remove the first column?
Use cut --complement -f1 or cut -f2- to skip field 1 and output everything from field 2 onward.

Master Linux with Professional eBooks

Curated IT eBooks covering Linux, DevOps, Cloud, and more

Browse Books →