- 论坛徽章:
- 0
|
[dwapp@dw_testdb ~]$ who
dwapp pts/0 Jun 23 20:46 (101.15.16.7)
dwapp pts/2 Jun 23 16:38 (101.15.13.6)
dwapp pts/6 Jun 22 10:02 (101.15.17.2)
dwapp pts/7 Jun 23 17:48 (101.15.16.8)
dwapp pts/8 Jun 22 10:16 (101.15.17.3)
dwapp pts/9 Jun 23 11:11 (101.15.16.34)
root pts/11 Jun 22 10:58 (101.15.16.33)
root pts/12 Jun 22 11:00 (101.15.16.32)
dwapp pts/13 Jun 23 11:11 (101.15.16.31)
dwapp pts/14 Jun 23 11:23 (101.15.16.24)
[color="#800080"]#使用 -c,取第一个字符
[dwapp@dw_testdb ~]$ who|cut -c1
d
d
d
d
d
d
r
r
d
d
[color="#800080"]#使用 -c,取1-5个字符
[dwapp@dw_testdb ~]$ who|cut -c1-5
dwapp
dwapp
dwapp
dwapp
dwapp
dwapp
root
root
dwapp
dwapp
[color="#800080"]#使用 -c,取6-最后个字符
[dwapp@dw_testdb ~]$ who|cut -c6-
pts/0 Jun 23 20:46 (101.15.16.7)
pts/2 Jun 23 16:38 (101.15.13.6)
pts/6 Jun 22 10:02 (101.15.17.2)
pts/7 Jun 23 17:48 (101.15.16.8)
pts/8 Jun 22 10:16 (101.15.17.3)
pts/9 Jun 23 11:11 (101.15.16.34)
pts/11 Jun 22 10:58 (101.15.16.33)
pts/12 Jun 22 11:00 (101.15.16.32)
pts/13 Jun 23 11:11 (101.15.16.31)
pts/14 Jun 23 11:23 (101.15.16.24)
[color="#800080"]#使用 -c,取1-5个字符,和35-最后个字符
[dwapp@dw_testdb ~]$ who|cut -c1-5,35-
dwapp (101.15.16.7)
dwapp (101.15.13.6)
dwapp (101.15.17.2)
dwapp (101.15.16.8)
dwapp (101.15.17.3)
dwapp (101.15.16.34)
root (101.15.16.33)
root (101.15.16.32)
dwapp (101.15.16.31)
dwapp (101.15.16.24)
[color="#800080"]# 使用 -d 和 -f
[dwapp@dw_testdb yuechaotian]$ cat passwd
root:x:0:0:root:/root:/bin/bash
lp:x:4:7:lp:/var/spool/lpd:/sbin/nologin
sync:x:5:0:sync:/sbin:/bin/sync
shutdown:x:6:0:shutdown:/sbin:/sbin/shutdown
halt:x:7:0:halt:/sbin:/sbin/halt
operator:x:11:0:operator:/root:/sbin/nologin
gopher:x:13:30:gopher:/var/gopher:/sbin/nologin
[dwapp@dw_testdb yuechaotian]$ cat passwd|cut -d: -f1,7
root:/bin/bash
lp:/sbin/nologin
sync:/bin/sync
shutdown:/sbin/shutdown
halt:/sbin/halt
operator:/sbin/nologin
gopher:/sbin/nologin
[color="#800080"]#也可以输入文件
[dwapp@dw_testdb yuechaotian]$ cut -d: -f1,7 ./passwd
root:/bin/bash
lp:/sbin/nologin
sync:/bin/sync
shutdown:/sbin/shutdown
halt:/sbin/halt
operator:/sbin/nologin
gopher:/sbin/nologin
[color="#800080"]#-d默认为制表符
[dwapp@dw_testdb yuechaotian]$ cat score
yuechaotian 80
oratea 79
yuexingtian 90
hot_dog 89
[dwapp@dw_testdb yuechaotian]$ cut -f2 score
80
79
90
89
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u/30637/showart_1975403.html |
|