Linux Command Reference ยท Text Processing
Linux cut command
Reference for the Linux cut command: extract fields with -d and -f, characters with -c, bytes with -b, ranges, complement and the limits of cut with spaces.
cut extracts parts of every line of its input: selected fields separated by a delimiter (-f), selected character positions (-c) or selected bytes (-b). It is a small, fast tool for tables with a clear separator, such as /etc/passwd, CSV without quoting, or fixed-width output.
cut does not reorder: fields always come out in their original order, no matter how you list them. For rearranging or for variable whitespace use awk.
cut OPTION... [FILE]...
Try it
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Press Run (or Ctrl + Enter) to see the result here.
Program input ยท what you'd type while the program runs
Type the answers before you press Run, one per line. Each time the program reads a line (with read or cat), it gets the next line from this box.
Syntax
cut -b LIST [FILE]... cut -c LIST [FILE]... cut -f LIST [-d DELIM] [-s] [FILE]...
LIST is a comma-separated set of numbers and ranges, counted from 1: 3, 1,4, 2-5, -3 (up to 3), 4- (from 4).
| Option | Description |
|---|---|
-f LIST |
Select fields. |
-d DELIM |
Field delimiter, a single character (default tab). |
-s, --only-delimited |
With -f, skip lines that contain no delimiter. |
-c LIST |
Select characters by position. |
-b LIST |
Select bytes by position. |
--complement |
Print everything except the selected parts. |
--output-delimiter=STR |
Join selected fields with STR instead of the input delimiter. |
-z |
Lines end with NUL. |
Returns: 0 on success, 1 on a usage error or unreadable file.
Usage notes
- One delimiter character only.
-d', '(comma and space) is an error. Convert multi-character separators first withsedortr. - Repeated delimiters make empty fields.
a bwith-d' 'has fieldsa, empty,b. Squeeze runs withtr -s ' 'or useawk '{print $2}', which splits on any run of blanks. - Order cannot change:
cut -f3,1prints field 1 then field 3. Useawk -F: '{print $3, $1}'orpastewith separate cuts to reorder. - Quoted CSV (
"a,b",c) is not understood.cutsplits at every delimiter even inside quotes. Use a real CSV parser for those files. - Multibyte text. GNU
cutmay still count bytes for-c, so a multibyte UTF-8 character can be split. Test with an accented letter before relying on-cfor non-ASCII data, or useawkwith a UTF-8 aware implementation. - Lines with too few fields give an empty line for
-f5when the line has a delimiter, and the whole line when it has none (unless-s). - Trailing newline is preserved per line; an unterminated last line is printed with a newline added.
- Typical combination:
cut -d: -f7 /etc/passwd | sort | uniq -ccounts login shells.