Linux cut Command: Extract Characters and Fields

cut selects and outputs specified bytes, characters, or delimiter-based fields from each input line. It is convenient for simple column extraction, but it is not a complex CSV parsing tool.

What is the cut command?

The field mode -f uses a tab as the default delimiter. To use a colon or a comma, specify -d as well. Choose -c or -b considering implementation and character encoding.

Basic syntax

cut -d 'delimiter' -f field_number [file...]

Installed implementations and options may vary depending on the distribution. Check the description for your system with man cut.

Examples

Extracting colon-delimited fields

Extract the first field from the system account list.

cut -d ':' -f 1 /etc/passwd

Selecting multiple fields

Fields specified with commas are output in the order of the original input.

cut -d ':' -f 1,7 /etc/passwd

Extract character range

Used when looking at the beginning of each line.

cut -c 1-8 sample.txt

Results of extracting fields using a delimiter

This is an example of extracting only the first field from two lines separated by a colon. -d is the delimiter, and -f is the field number to select.

printf 'alpha:100\nbeta:200\n' | cut -d: -f1

Example output:

alpha
beta

cut -d ' ' -f2 cannot reliably parse text with multiple consecutive spaces by columns. For such data, awk is suitable. Formats where a delimiter can appear inside quotes, like CSV, cannot be accurately handled by cut alone, so use a dedicated CSV parser.

Main Options and Format

Options/Format Description
-d delimiter Specify the field separator character.
-f list Selects the field number or range to output.
-c list Selects character positions.
-b list Select byte positions.
-s Do not print lines without field delimiters.

Precautions when using

cut -d ',' does not understand commas inside quotes or multi-line CSV fields. For such data, use a CSV-specific parser. Lines without delimiters are printed as is by default, so add -s if necessary.

Frequently Asked Questions

Can multiple columns separated by spaces also be extracted with cut?

If the width of consecutive spaces is inconsistent, the field numbers may be misaligned. Such input is usually better handled by awk.

Official Documentation

You can check the exact behavior of options and implementation differences in the official cut documentation.

More in This Category
Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Linux Tutorial / File Types and Metadata: ls, file, stat, and readlink

Learn what ls, file, stat, and readlink each reveal about a Linux file, including type, size, timestamps, and symbolic-link targets.

Linux last Command: Review Login and Reboot History

Linux last Command: Review Login and Reboot History

Learn how to use the Linux last command to review user login sessions, system reboots, and shutdown history, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux split Command: Divide Large Files into Smaller Parts

Linux split Command: Divide Large Files into Smaller Parts

Learn how to divide Large Files into Smaller Parts with the Linux split command, including practical examples, key options, and important precautions.

Linux tr Command: Translate and Delete Characters

Linux tr Command: Translate and Delete Characters

Learn how to translate and Delete Characters with the Linux tr command, including practical examples, key options, and important precautions.

Linux sync Command: Flush Buffered Writes to Storage

Linux sync Command: Flush Buffered Writes to Storage

Learn how to flush Buffered Writes to Storage with the Linux sync command, including practical examples, key options, and important precautions.

Linux gunzip Command: Decompress gzip Files

Linux gunzip Command: Decompress gzip Files

Learn how to decompress gzip Files with the Linux gunzip command, including practical examples, key options, and important precautions.

Linux mktemp Command: Create Secure Temporary Files and Directories

Linux mktemp Command: Create Secure Temporary Files and Directories

Learn how to create unpredictable temporary files and directories with Linux mktemp, use templates and TMPDIR, clean up with trap, and avoid unsafe dry runs.

Linux sort Command: Sort Text Lines

Linux sort Command: Sort Text Lines

Learn how to sort text lines with the Linux sort command, including practical examples, key options, and important precautions.

Linux sed Command: Search and Replace Text Streams

Linux sed Command: Search and Replace Text Streams

Learn how to search and Replace Text Streams with the Linux sed command, including practical examples, key options, and important precautions.

Linux paste Command: Join Corresponding Lines Side by Side

Linux paste Command: Join Corresponding Lines Side by Side

Learn how to join Corresponding Lines Side by Side with the Linux paste command, including practical examples, key options, and important precautions.