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列的区域
【推荐】还在用 ECharts 开发大屏?试试这款永久免费的开源 BI 工具!
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步