cut pick columns from each line
cut extracts columns from each line, either by delimiter-separated field number or by character position. It is simpler and faster than awk when all you need is a column or two.
Availability Preinstalled on macOS, Linux and BSD
Syntax
cut -d delimiter -f fields [file ...]
Common options
| Option | What it does |
|---|---|
-d C | Use the character C as the field delimiter (default: tab) |
-f LIST | Fields to keep, such as 1,3 or 2-4 |
-c LIST | Character positions to keep, such as 1-10 |
Examples
First and third CSV columns
cut -d, -f1,3 simple.csv
User names from /etc/passwd
cut -d: -f1 /etc/passwd
First 10 characters of each line
cut -c1-10 app.log
Use cut with sqx
Take a column from sqx output
TSV output works with cut's default tab delimiter.
sqx -f users=users.csv -o tsv -no-output-header "SELECT id, email FROM users" | cut -f2
Use sqx when the CSV has quoted fields
cut splits on every comma, even inside quotes. sqx parses CSV properly and selects columns by name.
sqx -f users=users.csv "SELECT name, email FROM users"
Full documentation
This page covers the essentials. For every option, see the official documentation:
Or read the manual in your terminal: man cut