cut command Linux Examples

Examples of the Linux 'cut' Command

Introduction to examples of using the Linux 'cut' command.

Shou Arisaka
2 min read
Nov 21, 2025

Examples of using the Linux “cut” command.

The cut command is a command that extracts and displays specified strings from each line of a file.

2019-01-19 21:43:34 ⌚  541e5aed5dcf in /docker
○ → printf "hogefuga" | cut -c 2-4
oge

2019-01-19 21:43:59 ⌚  541e5aed5dcf in /docker
○ → printf "hogefuga" | cut -c -2
ho

2019-01-19 21:44:08 ⌚  541e5aed5dcf in /docker
○ → printf "hogefuga" | cut -c 4-
efuga

2019-01-19 21:49:11 ⌚  541e5aed5dcf in /docker
○ → printf "hoge,fuga,foo,bar,baz" | cut --fields 2-4 --delimiter ,
fuga,foo,bar

The above commands are executed in the following steps:

  • The printf command outputs the string “hogefuga” to standard output.
  • The cut command extracts and displays characters 2 through 4 of the string “hogefuga”.
  • The cut command extracts and displays from the beginning through the 2nd character of the string “hogefuga”.
  • The cut command extracts and displays from the 4th character to the end of the string “hogefuga”.
  • The printf command outputs the string “hoge,fuga,foo,bar,baz” to standard output.
  • The cut command extracts and displays fields 2 through 4 of the string “hoge,fuga,foo,bar,baz”.
  • The cut command specifies ”,” as the field delimiter for the string “hoge,fuga,foo,bar,baz” and extracts and displays fields 2 through 4.

Share this article

Shou Arisaka Nov 21, 2025

🔗 Copy Links