Open System Services Shell and Utilities Reference Manual (G06.25+, H06.03+)

cut(1) OSS Shell and Utilities Reference Manual
You must specify the -b ag (to select bytes), the -c ag (to select characters), or the -f ag (to
select elds). The list argument (see the -b, -c, and -f ags) must be a space-separated or
comma-separated list of positive numbers and ranges. Ranges can be in three forms:
Two positive numbers separated by a - (dash), as in the form low-high, which
represents all elds from the rst number to the second number.
A positive number preceded by a - (dash), as in the form -high, which represents
all elds from eld number 1 to that number.
A positive number followed by a - (dash), as in the form low-, which represents
that number to the last eld, inclusive.
The elements in list can be repeated, can overlap, and can be specied in any order.
Some sample list specications are as follows:
1,4,7 or 147
First, fourth, and seventh bytes or elds.
1-3,8 First through third and eighth bytes or elds.
-5,10 First through fth and tenth bytes or elds.
3- Third through last bytes or elds.
The elds specied by list can be a xed number of byte positions, or the length can vary
from line to line and be marked with a eld delimiter character, such as a tab character.
You can also use the grep command to make horizontal cuts through a le and the paste
command to put the les back together. To change the order of columns in a le, use the
cut and paste commands.
EXAMPLES
To display several elds of each line of a le, enter:
cut -f 1,5 -d : /etc/passwd
This command displays the login name and full username elds of the system password le.
These are the rst and fth elds (-f 1,5) separated by colons (-d :).
So, if the /etc/passwd le looks like this:
su:UHuj9Pgdvz0J":0:0:User with special privileges:/:
daemon:*:1:1::/etc:
bin:*:2:2::/usr/bin:
sys:*:3:3::/usr/src:
adm:*:4:4:System Administrator:/usr/adm:
pierre:*:200:200:Pierre Harper:/u/pierre:
joan:*:202:200:Joan Brown:/u/joan:
Then cut -f 1,5 -d : /etc/passwd produces this output:
su:User with special privileges
daemon:
bin:
sys:
adm:System Administrator
pierre:Pierre Harper
joan:Joan Brown
280 Hewlett-Packard Company 527188-003