cut field column extraction command
Command syntax: cut [options] filename
command options: -f column number, extraction columns; -d delimiter, in accordance with the specified separator split columns.
Example:
[root@192 cut]# cat score.txt
Id Name Gender Score
1 zhangsan M 90
2 lisi M 88
3 wangwu M 98
4 zhaoliu N 97
5 NangongYi M 100
Example: I want to extract all grades - cut -f 4 score.txt
[root@192 cut]# cut -f 4 score.txt
Score
90
88
98
97
100
[root@192 cut]#
Example: If you want to recall names and scores - cut -f 2,4 score.txt
[root@192 cut]# cut -f 2,4 score.txt
Name Score
zhangsan 90
lisi 88
wangwu 98
zhaoliu 97
NangongYi 100
[root@192 cut]#
Example: From passwd file, the ":" as a separator, extraction columns 1,3 - cut -d ":" -f 1,3 / etc / passwd
[root@192 cut]# cut -d ":" -f 1,3 /etc/passwd
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
uucp:10
operator:11
games:12
gopher:13
ftp:14
nobody:99
dbus:81
vcsa:69
rpc:32
abrt:173
haldaemon:68
ntp:38
saslauth:499
postfix:89
avahi:70
rpcuser:29
nfsnobody:65534
sshd:74
tcpdump:72
oprofile:16
user1:500
[root@192 cut]#
Then, cut the role of these yet? Not, cut in the real operation, combined with the grep command, it will play the greatest role.
Knowledge:
the file system user login is "/ sbin / nologiin"; ordinary users to log file is "/ bin / bash"
Example: I want to know all the new username average user Linux system - cat / etc / passwd | grep / bin / bash | cut -d ":" -f 1
[root@192 cut]# cat /etc/passwd | grep /bin/bash | cut -d ":" -f 1
root
user1
user2
user3
[root@192 cut]#
Limitations cut command
Example:
[root@192 cut]# df -h
文件系统 容量 已用 可用 已用%% 挂载点
/dev/sda3 17G 2.6G 14G 17% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 985M 40M 896M 5% /boot
Example: I want to extract the amount of / dev / sda3 of
[root@192 cut]# df -h | cut -f 5
/dev/sda3 17G 2.6G 14G 17% /
tmpfs 499M 0 499M 0% /dev/shm
/dev/sda1 985M 40M 896M 5% /boot
As a result, it did not show what we want out! Why is that? Limitations Cut command on the show! cut command limitation is that it can not be extracted separator is not "tabs" (tab) characters .