coreutils: The cut command
1
1 The ‘cut’ Command
1 =================
1
1 The next program we’ll look at is the ‘cut’ command. This program cuts
1 out columns or fields of input data. For example, we can tell it to
1 print just the login name and full name from the ‘/etc/passwd’ file.
1 The ‘/etc/passwd’ file has seven fields, separated by colons:
1
1 arnold:xyzzy:2076:10:Arnold D. Robbins:/home/arnold:/bin/bash
1
1 To get the first and fifth fields, we would use ‘cut’ like this:
1
1 $ cut -d: -f1,5 /etc/passwd
1 ⊣ root:Operator
1 ...
1 ⊣ arnold:Arnold D. Robbins
1 ⊣ miriam:Miriam A. Robbins
1 ...
1
1 With the ‘-c’ option, ‘cut’ will cut out specific characters (i.e.,
1 columns) in the input lines. This is useful for input data that has
1 fixed width fields, and does not have a field separator. For example,
1 list the Monday dates for the current month:
1
1 $ cal | cut -c 3-5
1 ⊣Mo
1 ⊣
1 ⊣ 6
1 ⊣ 13
1 ⊣ 20
1 ⊣ 27
1