cut -c list [file ...]
cut -f list [-d delim] [-s] [file ...]
cut -b list [-n] [file ...]
Writes portions of each line from each file to standard output. file is not specified or file is a single dash (-) cut reads from standard input. list can be in terms of column position or fields delimited by a delim character.
list | n1 n2,n3,n4 n5 | a set of increasing numbers and/or ranges separated by comma or whitespace.
|
range | n1-n2 | inclusive. |
-n
| numbers or ranges preceded by a dash selects all fields or columns from 1 to the first number.
| |
n-
| numbers or ranges followed by a dash selects all fields or columns from the last number to the end of the line.
| |
numbers and ranges may be repeated, overlap, and in any order.
| ||
| It is not an error to specify fields or columns not present in the input line. | ||
-f list |
ENVIRONMENT
The LANG, LC_ALL and LC_CTYPE environment variables affect cut .
see environ, locale.
EXAMPLES
Extract users' login names and shells from the system passwd file as name:shell pairs (i.e. 1st and 7th columns.:
/etc/passwd
root:x:0:0:root:/root:/bin/bash
bin:x:1:1:bin:/bin:/sbin/nologin
daemon:x:2:2:daemon:/sbin:/sbin/nologin
cut -d : -f 1,7 /etc/passwd
root:/bin/bash
bin:/sbin/nologin
daemon:/sbin/nologin
Show the names and login times of the currently logged in users:
dgerman console Dec 28 11:26 samual ttys000 Dec 30 14:44 dger ttys001 Dec 30 14:44
who | cut -c -9,26-
dgerman 11:26 samual 14:44 dger 14:44
exits returning 0 on success, and >0 if an error occurs.
|
The Mac OSX darwin BSD version as of 10.5.6 exits if a copyright symbol (x'A9', © ), left double quote (x'93', “) etc, B8, D1, C0, CF, C2, D8, D4 is encountered with the message: Illegal byte sequence and a exit status of 0.
This is easily corrected with:
|