Unix cut command: Reference and Examples

Last updated:
Table of Contents

WIP Alert This is a work in progress. Current information is correct but more content may be added in the future.

Simplest possible example

Simple template: cut -d<delimiter> -f<part-to-extract>

$ echo "foo bar baz" | cut -d' ' -f1
# outputs "foo"
$ echo "foo bar baz" | cut -d' ' -f3
# outputs "bar"
$ echo "foo bar baz" | cut -d' ' -f6
# outputs nothing because there aren't 6 parts available

Split on one or more spaces

Use tr first and pipe the result to cut:

$ echo "foo     bar   baz" | tr -s ' ' | cut -d' ' -f2
# outputs "bar"

This is useful to parse the output of commands such as ls:

$ ls -lha ~/ | grep profile
-rw-rw-r--   1 felipe felipe  200 Abr 21  2017 .bash_profile
-rw-r--r--   1 felipe felipe 1000 Jul  5 05:21 .profile

Use -f6 to indicate you want to extract the 6th path (month name):

$ ls -lha ~/ | grep profile | tr -s ' ' | cut -d' ' -f6
Abr
Jul

Dialogue & Discussion