首页 > 其他 > 详细

字符截取:cut

时间:2017-08-13 15:51:36      阅读:238      评论:0      收藏:0      [点我收藏+]

cut 选项 文件名

-f 列号  提取第几列

-d 分隔符  指定分隔符把行分成多列

[root@localhost ~]# cat testfile
no.     name    sex     score
1       zhangsan        m       88
2       lisi    f       89
3       wangwu  m       87
[root@localhost ~]# cut -f 2 testfile  注释:默认分隔符是制表符\t
name
zhangsan
lisi
wangwu
[root@localhost ~]# cut -f 2,4 testfile
name    score
zhangsan        88
lisi    89
wangwu  87
[root@localhost ~]# cat testfile
no.     na:me   sex     sco:re
1       zhang:san       m       8:8
2       li:si   f       8:9
3       wang:wu m       8:7
[root@localhost ~]# cut -f 1,3 -d : testfile
no.     na:re
1       zhang:8
2       li:9
3       wang:7

 

root@localhost ~]# cut -f 1 -d : /etc/passwd|grep xiong
xiongjiawei
[root@localhost ~]# grep xiong /etc/passwd|cut -d : -f 1
xiongjiawei
[root@localhost ~]# grep xiong /etc/passwd|cut -d ":" -f 1
xiongjiawei
[root@localhost ~]# grep xiong /etc/passwd|cut -f 1 -d :
xiongjiawei
[root@localhost ~]# grep xiong /etc/passwd|cut -f 1 -d ":" 
xiongjiawei 

 

字符截取:cut

原文:http://www.cnblogs.com/xiongjiawei/p/7353639.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!