[Chapter 35] 35.14 Cutting Columns or Fields with cut
Author: Jerry Peek, Tim O'Reilly & Mike Loukides
Date: 1998-08-04T21:48:15Z

#

| Chapter 35 You Can't Quite Call This Editing |

## 35.14 Cutting Columns or Fields with cut

cut+paste | System V includes a nifty command called cut that lets you select a list of columns or fields from one or more files. We've also included a public-domain version on the disc, for those of you whose systems do without.

You must specify either the -c option to cut by column or -f to cut by fields. (Fields are separated by tabs unless you specify a different field separator with -d. Use quotes (8.14) if you want a space or other special character as the delimiter.)

The column(s) or field(s) to cut must follow the option immediately, without any space. Use a comma between separate values and a hyphen to specify a range (e.g., `1-10`, `15`, `20`, or `50-`).

cut is incredibly handy. Here are some examples:

- Find out who is logged in, but list only login names:

      who
      % who | cut -d" " -f1

- Extract usernames and real names from /etc/passwd (36.3):

  >     % cut -d: -f1,5 /etc/passwd

- Cut characters in the fourth column of file, and paste them back as the first column in the same file:

      paste
      % cut -c4 file | paste - file

- TOR, DG

35.13 Other Conversions with dd |  | 35.15 Cutting Columns with colrm