Next: , Previous: , Up: Opening the software toolbox   [Contents][Index]

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
-|  6
-| 13
-| 20
-| 27