Skip to main content

The cut command can be used to display only specific columns from a text file or other command outputs.

# To cut out the first sixteen characters of each line of STDIN:
cut -c 1-16

# To cut out the first sixteen characters of each line of the given files:
cut -c 1-16 <file>

# To cut out everything from the 3rd character to the end of each line:
cut -c3-

# To cut out the fifth field of each line, using a colon as a field delimiter (default delimiter is tab):
cut -d':' -f5

# To cut out the 2nd and 10th fields of each line, using a semicolon as a delimiter:
cut -d';' -f2,10

# To cut out the fields 3 through to the end of each line, using a space as a delimiter:
cut -d' ' -f3-

# ---

# display the 1st field (employee name) from a colon delimited file:
$ cut -d: -f 1 names.txt
    Emma Thomas
    Alex Jason
    Madison Randy
    Sanjay Gupta
    Nisha Singh

# display 1st and 3rd fields from a colon delimited file:
$ cut -d: -f 1,3 names.txt
    Emma Thomas:Marketing
    Alex Jason:Sales
    Madison Randy:Product Development
    Sanjay Gupta:Support
    Nisha Singh:Sales

# display the first 8 characters of every line in a file:
$ cut -c 1-8 names.txt
    Emma Tho
    Alex Jas
    Madison
    Sanjay G
    Nisha Si

# display login names for all the users in the system:
$ cut -d: -f1 /etc/passwd

# displays the total available system memory:
$ free | tr -s ' ' | sed '/^Mem/!d' | cut -d" " -f2

# to cut out the third field of text or stdoutput that is delimited by a #:
$ cut -d# -f3