cut--修剪小能手

cut命令

cut原理:以每一行位一个处理对象。

参数选项 解释说明
-b 以字节为单位进行分割
-c 以字符为单位进行分割(对切割中文有奇效)
-d 自定义分隔符号,默认以tab为分隔符

1:-b  参数的例子
[root@localhost tmp]# cat test.txt    
abcdefg
abcdefg
abcdefg


[root@localhost tmp]# cut -b 3 test.txt   ###只输出第三个字节
c
c
c

[root@localhost tmp]# cut -b -3 test.txt   ###输出从开始到第3个字节[闭区间]
abc
abc
abc

[root@localhost tmp]# cut -b 3- test.txt   ###输出从第3个字节到行末尾[闭区间]
cdefg
cdefg
cdefg

2:自定义分隔符号
[root@localhost tmp]# cut -d : -f 1  /etc/passwd    #-f 1:选择输出第1个区域
root
bin
daemon
adm
lp
sync
shutdown

[root@localhost tmp]# cut -d : -f 3-5 /etc/passwd     ###显示3到5列的区域

猜你喜欢

转载自www.cnblogs.com/zhoujun007/p/cut.html