The cut command reads lines from a file or standard input and prints specific portions based on fields, characters, or bytes. It works on one line at a time — no regex, no scripting — just fast column extraction at the terminal. If you’re new to working with text in the terminal, it’s one of the first tools worth learning.
Bash cut Command Syntax
The basic syntax takes an option and a file:
cut [OPTION] [FILE]
Without a file, cut reads from standard input, which makes it useful inside pipelines. Every invocation requires at least one of -f, -c, or -b. Calling cut without any option returns an error.
bash cut Command Flags and Options
| Flag | Long Form | Purpose |
|---|---|---|
-f | --fields | Select by field number (most common) |
-d | --delimiter | Set a custom input delimiter (default: tab) |
-c | --characters | Select by character position |
-b | --bytes | Select by byte position |
--complement | — | Print everything except the selected fields |
-s | --only-delimited | Skip lines with no delimiter |
--output-delimiter | — | Use a different character between output fields |
The cut man page lists the full specification for each flag, including edge cases for byte ranges in multibyte locales.
Relative frequency of bash cut flag usage in shell scripts
How to Extract a Single Column with bash cut
Using the sample file example_data.txt:
Kai Refsnes 30,Norway
Robin Smith 25,Denmark
Sienna Davis 40,Germany
Tab is the default delimiter, so pulling the first field needs nothing beyond -f1:
cut -f1 example_data.txt
Kai
Robin
Sienna
Setting a Custom Delimiter with -d
Tab separators don’t cover every case. CSV files, /etc/passwd, and many log formats use colons or commas. Pass -d with a single character to change the delimiter:
cut -d',' -f1 example_data.txt
Kai Refsnes 30
Robin Smith 25
Sienna Davis 40
With a comma as the boundary, everything before the first comma counts as column one. The -d flag accepts exactly one character — passing two or more triggers the error cut: delimiter must be a single character.
Selecting Multiple or Range Columns
The -f flag accepts ranges and comma-separated lists. Use 1-2 for a range and 1,3 for non-consecutive fields:
cut -f1-2 example_data.txt
Kai Refsnes
Robin Smith
Sienna Davis
To grab columns two through three:
cut -f2-3 example_data.txt
Refsnes 30,Norway
Smith 25,Denmark
Davis 40,Germany
Range notation follows a simple pattern: N for a single field, N-M for a span, N- for everything from N to the end of the line.
Using –complement to Exclude Fields
Instead of listing what you want, --complement lets you list what to drop. It prints every field except the ones specified:
cut --complement -f1 example_data.txt
Refsnes 30,Norway
Smith 25,Denmark
Davis 40,Germany
Column one is gone; everything else prints normally. The --complement flag is GNU-only and not available on macOS’s built-in BSD version of cut.
Extracting by Character Position
The -c flag works on character index rather than delimiters. It’s useful for fixed-width logs or data where columns aren’t separated by a character:
cut -c1-3 example_data.txt
Kai
Rob
Sie
For multibyte characters (UTF-8 text), use -b instead to target exact byte positions rather than character counts.
Using bash cut in Pipelines
Because cut reads from standard input, it connects naturally with other commands via pipes. Pulling just the usernames from /etc/passwd takes one line:
cut -d':' -f1 /etc/passwd
Chaining with sort and uniq removes duplicates and alphabetizes the output in a single pass. The bash shell usage statistics for 2026 confirm that bash remains the dominant shell for scripting, making fluency with tools like cut practically universal in shell environments.
cut -d':' -f1 /etc/passwd | sort | uniq
When the output delimiter should differ from the input one, --output-delimiter handles the conversion without needing sed:
cut -d',' -f1,3 --output-delimiter=':' example_data.txt
Common Errors and How to Fix Them
| Error | Cause | Fix |
|---|---|---|
cut: delimiter must be a single character |
More than one character passed to -d |
Use exactly one character, e.g. -d',' |
cut: fields and positions are numbered from 1 |
Zero used as a field number | Start field numbering at 1, not 0 |
| Entire line printed instead of a field | Delimiter not present in that line | Add -s to skip lines without the delimiter |
| Unexpected output on macOS | --complement not supported in BSD cut |
Use awk or install GNU coreutils via Homebrew |
bash cut Quick Reference
| Task | Command |
|---|---|
| First column (tab-separated) | cut -f1 file.txt |
| Comma-separated, column one | cut -d',' -f1 file.txt |
| Columns two through three | cut -f2-3 file.txt |
| All columns except the first | cut --complement -f1 file.txt |
| Characters 1 to 5 of each line | cut -c1-5 file.txt |
| Skip lines without the delimiter | cut -d':' -f1 -s file.txt |
| Change output delimiter | cut -d',' -f1,2 --output-delimiter=':' file.txt |
| Field from piped command | echo "a:b:c" | cut -d':' -f2 |
FAQs
What is the bash cut command used for?
The cut command extracts specific fields, characters, or bytes from each line of a file or input stream. It’s commonly used to parse CSV files, log files, and command output in shell scripts.
How do I use a custom delimiter with bash cut?
Use the -d flag followed by a single character, such as cut -d',' -f1 file.txt for comma-separated data. The default delimiter is a tab character.
What is the difference between -f, -c, and -b in cut?
-f selects by field using a delimiter, -c selects by character position, and -b selects by byte position. For ASCII files all three behave similarly, but -b and -c differ for multibyte characters.
Can I select non-consecutive fields with bash cut?
Yes. Use a comma-separated list with -f, such as cut -f1,3 file.txt to print the first and third fields. For a continuous range, use -f1-3.
How do I use bash cut with pipes?
Pipe the output of another command directly into cut, for example: cat /etc/passwd | cut -d':' -f1. No file argument is needed when reading from standard input.