cut command in Linux with examples
Last Updated : 11 Oct, 2025
The cut command in Linux is used to extract specific sections from each line of a file or input stream based on byte position, character, or field delimiter, and outputs the result to standard output.
Let us consider two files having name sample.txt contains 5 names of the Indian states and capitals respectively.
$ cat sample.txt
Running the cut command without an option results in an error:
$ cut sample.txt
We use the following command to display all available options and usage details for the cut command.
cut --help
After that we extract the 2nd and 3rd field from each lines
cut -d " " -f 2,3 sample.txt
- The command extracts the 2nd and 3rd fields from each line of
sample.txt, using a space (" ") as the delimiter. - It displays only the selected columns (e.g., state and capital names) from the input file.
Syntax of cut Command
The basic syntax of the cut command in Linux is:
cut OPTION... [FILE]..
`OPTION`defines how the Linux cut command behaves.- `
FILE` is the input file. If no file is specified, the cut command Unix reads from standard input (stdin).
Note: If FILE is not specified, `cut` reads from standard input (stdin).
Options Available in cut Command
Here is a list of the most commonly used options with the Linux cut command:
Option | Description |
|---|
-b, --bytes=LIST | Selects only the bytes specified in LIST (e.g., -b 1-3,7). |
|---|
-c, --characters=LIST | Selects only the characters specified in LIST (e.g., -c 1-3,7). |
|---|
-d, --delimiter=DELIM | Uses DELIM as the field delimiter character instead of the tab character. |
|---|
-f, --fields=LIS | Selects only the fields specified in LIST, separated by the delimiter character (default is tab). |
|---|
-n | Do not split multi-byte characters (no effect unless -b or -c is specified). |
|---|
--complement | Invert the selection of fields/characters. Print the fields/characters not selected. |
|---|
--output-delimiter | Changes the output delimiter for fields in the cut command bash. |
|---|
List without ranges:
It will extract and display the 1st, 2nd, and 3rd bytes (characters) from each line of the state.txt file
cut -b 1,2,3 state.txt
list without rangeList with ranges:
It will extract characters from positions 1 to 3, and then from 5 to 7, from each line of the file named state.txt
cut -b 1-3,5-7 state.txt
list with rangeIt uses a special form for selecting bytes from beginning upto the end of the line:
In this, 1- indicate from 1st byte to end byte of a line
cut -b 1- state.txt
special form with -b optionIn this, -3 indicate from 1st byte to 3rd byte of a line
cut -b -3 state.txt
special form -b optionCut by Character (-c) Using cut Command
-c (column): The -c option in the cut command Unix extracts characters. You can specify a list of character positions with commas or a range with a hyphen (-).
Tabs and backspaces are treated as single characters, and a valid character list is required to avoid errors.
Syntax:
cut -c [(k)-(n)/(k),(n)/(n)] filename
Here,k denotes the starting position of the character and n denotes the ending position of the character in each line, if k and n are separated by "-" otherwise they are only the position of character in each line from the file taken as an input.
It will extract and display the characters at positions 2, 5, and 7 from each line of the file named state.txt
cut -c 2,5,7 state.txt
Extract specific charactersThis cut in Unix command prints the 2nd, 5th, and 7th characters from each line.
It extracts and displays the first 7 characters from each line of the file named state.txt.
cut -c 1-7 state.txt
Extract first seven charactersAbove cut command prints first seven characters of each line from the file. Cut uses a special form for selecting characters from beginning upto the end of the line:
It extracts and displays the first character of each line from the file named state.txt.
cut -c 1- state.txt
selecting characters from beginning to end of line using -c optionAbove command prints starting from first character to end. Here in command only starting position is specified and the ending position is omitted.
cut -c -5 state.txt
selecting characters from beginning to end of line using -c optionAbove command prints starting position to the fifth character. Here the starting position is omitted and the ending position is specified.
Cut by Field (-f) Using cut Command
-f (field): The -f option in the cut command Linux is ideal for files without fixed-length lines. It extracts fields separated by a delimiter (default is tab). Use the Linux "cut -d" option to specify a custom delimiter, like a space.
Note: Space is not considered as delimiter in UNIX.
Syntax:
cut -d "delimiter" -f (field number) file.txt
Extract first field :
Like in the file state.txt fields are separated by space if -d option is not used then it prints whole line:
cut -f 1 state.txt
Extract first field using -f optionIf `-d` option is used then it considered space as a field separator or delimiter:
cut -d " " -f 1 state.txt
space as a field separator or delimiterCommand prints field from first to fourth of each line from the file.
cut -d " " -f 1-4 state.txt
Command prints field from first to fourthComplement Output (--complement) Using cut Command
--complement: As the name suggests it complement the output. This option can be used in the combination with other options either with -f or with -c.
cut --complement -d " " -f 1 state.txt
--complementIt removes the 5th character from each line of state.txt and prints the rest of the line.emoves the 5th character from each line of state.txt and prints the rest of the line.
cut --complement -c 5 state.txt
--complementOutput Delimiter (--output-delimiter) Using cut Command
--output-delimiter: By default the output delimiter is same as input delimiter that we specify in the cut with -d option. To change the output delimiter use the option --output-delimiter="delimiter".
cut -d " " -f 1,2 state.txt --output-delimiter='%'

Here cut command changes delimiter(%) in the standard output between the fields which is specified by using -f option .
Display Version (--version) Using cut Command
--version: This option is used to display the version of cut which is currently running on your system.
cut --version
display version of cut commandHow to use tail with pipes(|) in cut Command
The cut command in unix can be piped with many other commands. In the following example output of the cat command is given as input to the cut command with -f option to sort the state names coming from file state.txt in the reverse order.
cat state.txt | cut -d ' ' -f 1 | sort -r
using tail with pipe (|) in cut commandIt can also be piped with one or more filters for additional processing. Like in the following example, we are using cat, head and cut command and whose output is stored in the file name list.txt using directive(>).
cat state.txt | head -n 3 | cut -d ' ' -f 1 > list.txt
cat list.txt
redirecting output in different file
Explore
Linux/Unix Tutorial
5 min read
Getting Started with Linux
Installation with Linux
Linux Commands
Linux File System
Linux Kernel
Linux Networking Tools
Linux Process
Linux Firewall
Shell Scripting & Bash Scripting
My Profile