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
to cut by fields.
(Fields are separated by tabs
unless you specify a different field separator
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.,
is incredibly handy.
Here are some examples:
Find out who is logged in, but list only login names:
who | cut -d" " -f1
Extract usernames and real names from
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 -