cut命令
功能介绍
- 从文件的每一行剪去字节,字符或字段,并将这些字节、字符或字段输出至标准输出
语法格式
cut [option] [file]
选项说明
参数选项 |
解释说明 |
-b |
以字节为单位进行分割 |
-n |
取消分割多字节字符 |
-c |
以字节为单位进行分割 |
-d |
自定义分隔符 |
-f |
与-d一起使用,指定显示哪个区域 |
N |
第N个字节、字符或字段 |
N- |
从第N个字节、字符或字段开始直至结尾 |
N-M |
从N到M的字节、字符或字段 |
-M |
从第1 到到M的字节、字符或字段 |
范例
root@kali:~/Software# cat 1.txt
I want to study penetration testing!
root@kali:~/Software# cut -b 3 1.txt
w
root@kali:~/Software# cut -b 3-5 1.txt
wan
root@kali:~/Software# cut -b -3 1.txt
I w
root@kali:~/Software# cut -b 3- 1.txt
want to study penetration testing!
root@kali:~/Software# cut -b -3,3- 1.txt
I want to study penetration testing!
# cut -d : -f 1 /etc/passwd
root
daemon
bin
sys
<snip>
# cut -d : -f 3-5 /etc/passwd
0:0:root
1:1:daemon
2:2:bin
3:3:sys
4:65534:sync
网友评论