manpagez: man pages & more
info coreutils
Home | html | info | man

File: coreutils.info,  Node: The cut command,  Next: The sort command,  Prev: The who command,  Up: Opening the software toolbox

The ‘cut’ Command
=================

The next program we’ll look at is the ‘cut’ command.  This program cuts
out columns or fields of input data.  For example, we can tell it to
print just the login name and full name from the ‘/etc/passwd’ file.
The ‘/etc/passwd’ file has seven fields, separated by colons:

     arnold:xyzzy:2076:10:Arnold D. Robbins:/home/arnold:/bin/bash

   To get the first and fifth fields, we would use ‘cut’ like this:

     $ cut -d: -f1,5 /etc/passwd
     ⊣ root:Operator
     ...
     ⊣ arnold:Arnold D. Robbins
     ⊣ miriam:Miriam A. Robbins
     ...

   With the ‘-c’ option, ‘cut’ will cut out specific characters (i.e.,
columns) in the input lines.  This is useful for input data that has
fixed width fields, and does not have a field separator.  For example,
list the Monday dates for the current month:

     $ cal | cut -c 3-5
     ⊣Mo
     ⊣
     ⊣  6
     ⊣ 13
     ⊣ 20
     ⊣ 27

© manpagez.com 2000-2025
Individual documents may contain additional copyright information.