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 apt Command: Manage Packages on Debian and Ubuntu

Linux apt Command: Manage Packages on Debian and Ubuntu

Learn how to manage Packages on Debian and Ubuntu with the Linux apt command, including practical examples, key options, and important precautions.

Linux date Command: Display and Format the Current Time

Linux date Command: Display and Format the Current Time

Learn how to display and Format the Current Time with the Linux date command, including practical examples, key options, and important precautions.

Linux systemctl Command: Manage systemd Services

Linux systemctl Command: Manage systemd Services

Learn how to manage systemd Services with the Linux systemctl command, including practical examples, key options, and important precautions.

Linux modinfo Command: Inspect Kernel Module Details

Linux modinfo Command: Inspect Kernel Module Details

Learn how to inspect Kernel Module Details with the Linux modinfo command, including practical examples, key options, and important precautions.

Linux locate Command: Search Indexed File Paths Quickly

Linux locate Command: Search Indexed File Paths Quickly

Learn how Linux locate searches a filename database, how updatedb affects freshness, how to limit and filter matches, and when find is the better tool.

Linux unalias Command: Remove Command Aliases

Linux unalias Command: Remove Command Aliases

Learn how to use the Linux unalias command to remove one or all aliases from the current shell session, with essential options, practical examples, output interpretation, and common troubleshooting tips.

Linux Administration Memo: Essential Commands and System Checks

Linux Administration Memo: Essential Commands and System Checks

A compact Linux administration reference for checking system information, processes, storage, networking, users, permissions, services, and logs.

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Linux Tutorial / Manage Files and Directories: Create, Copy, Move, and Delete

Practice creating, copying, renaming, moving, and deleting files and directories in a dedicated folder while checking each result safely.

How to Check IP Addresses on Linux

How to Check IP Addresses on Linux

Learn how to check private and public IP addresses on Linux, identify the active interface and route, and distinguish IPv4, IPv6, and externally visible addresses.

Linux dirname Command: Extract the Directory Part of a Path

Linux dirname Command: Extract the Directory Part of a Path

Learn how to use the Linux dirname command to remove the final component of a path and return its directory portion, with essential options, practical examples, output interpretation, and common troubleshooting tips.