cut(1)
Remove sections from each line of files or stdin.
Synopsis
cut [OPTION]... [FILE]...Description
The cut command removes (cuts out) sections from each line of input based on character position, byte position, or field delimiter. It's commonly used to extract columns from structured text like CSV files, output from other commands, or log files.
By default, cut uses a tab character as the field delimiter. You can specify a different delimiter with -d and select which fields to keep with -f. Alternatively, select by character position with -c or byte position with -b.
Common options
| Flag | What it does |
|---|---|
-f LIST | Select only these fields (comma or range separated, e.g., 1,3 or 1-3) |
-d DELIM | Use DELIM as the field separator instead of tab |
-c LIST | Select only these character positions (1-indexed, e.g., 1-5,10) |
-b LIST | Select only these byte positions |
--complement | Invert selection; print all fields/characters except those specified |
-s | Skip lines that don't contain the delimiter (used with -f) |
-z | Use NUL (null character) as the line terminator instead of newline |
--output-delimiter=STRING | Use STRING for output field separator (default: same as input) |
Examples
Extract the 1st and 3rd fields (username and UID) from /etc/passwd using ':' as delimiter
cut -f 1,3 /etc/passwdExtract fields 2 and 4 from a comma-separated CSV file
cut -d',' -f 2,4 data.csvDisplay characters 1-20 and 72 onward from ps output (user and command columns)
ps aux | cut -c 1-20,72-Extract username, full name (GECOS), and shell from passwd file
cut -d: -f1,5,7 /etc/passwdPrint first 5 characters of a string ('hello')
echo 'hello world' | cut -c 1-5Extract first 3 tab-separated fields and output with pipe delimiter
cut -f 1-3 --output-delimiter='|' data.tsvExtract specific space-separated columns from a log file
cut -d' ' -f2,4,6 logfile.txtExtract all fields from field 2 to the end of each line
cut -f 2- data.txt