shell入门-cut命令

命令:cut

选项:-d:-f  指定第几段由“:(分割符)”分割的段

        -c    指定第几个字符

说明:选取命令,选取一段数据中我们想要的,一般是针对每行来分析选取的

[root@wangshaojun ~]# cat /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

......

[root@wangshaojun ~]# cut -d: -f 4 /etc/passwd//////指定单个段
0
1
2

....

[root@wangshaojun ~]# cut -d: -f 3,1,4 /etc/passwd ////指定多个段
root:0:0
bin:1:1
daemon:2:2

.......

////////////////////////////////////////////////////////////////////////////////////////

[root@wangshaojun ~]# cut -c 10 /etc/passwd /////指定第一个字符
0
:
2

.....

[root@wangshaojun ~]# cut -c 1-10 /etc/passwd //////指定区间字符
root:x:0:0
bin:x:1:1:
daemon:x:2

......

//////////////////////////////////////////////

总结 cut  常用选项-d: -f ;  -c

原文地址:https://www.cnblogs.com/wangshaojun/p/4966635.html