shell字符截取命令之cut命令的实例详解

一 语法

cut [选项] 文件名
选项:
-f 列号:提取第几列
-d 分隔符:按照指定分隔符分割列

 二 实战

[root@localhost ~]# cat student.txt
1 furong F 85
2 fengj F 60
3 cang F 70
[root@localhost ~]# cut -f 2 student.txt
furong
fengj
cang
[root@localhost ~]# cut -f 2,4 student.txt
furong 85
fengj 60
cang 70
[root@localhost ~]# grep "/bin/bash" /etc/passwd|grep -v "root"|cut -f 1 -d ":"
cakin24
test
cls
[root@localhost ~]# cut -d ":" -f 1,3 /etc/passwd
root:0
bin:1
daemon:2
adm:3
lp:4
sync:5
shutdown:6
halt:7
mail:8
operator:11
games:12
ftp:14
nobody:99
systemd-bus-proxy:999
systemd-network:998
dbus:81
polkitd:997
abrt:173
unbound:996
tss:59
colord:995
usbmuxd:113
geoclue:994
rpc:32
rtkit:172
chrony:993
radvd:75
qemu:107
avahi-autoipd:170
setroubleshoot:992
rpcuser:29
nfsnobody:65534
saslauth:991
libstoragemgmt:990
pulse:171
gdm:42
gnome-initial-setup:989
avahi:70
sshd:74
postfix:89
ntp:38
tcpdump:72
cakin24:1000
test:1003
cls:1001

 三 cut命令的局限

df -h|cut -d " " -f 1,3

只能分割比较规则的文本,一般分割符是制表符或冒号。

不能简单的用空格作为分割符。

如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!

标签:
shell,cut,shell,cut字符串的详解,shell,cut使用方法

免责声明:本站文章均来自网站采集或用户投稿,网站不提供任何软件下载或自行开发的软件! 如有用户或公司发现本站内容信息存在侵权行为,请邮件告知! 858582#qq.com
内蒙古资源网 Copyright www.nmgbbs.com

评论“shell字符截取命令之cut命令的实例详解”

暂无“shell字符截取命令之cut命令的实例详解”评论...

RTX 5090要首发 性能要翻倍!三星展示GDDR7显存

三星在GTC上展示了专为下一代游戏GPU设计的GDDR7内存。

首次推出的GDDR7内存模块密度为16GB,每个模块容量为2GB。其速度预设为32 Gbps(PAM3),但也可以降至28 Gbps,以提高产量和初始阶段的整体性能和成本效益。

据三星表示,GDDR7内存的能效将提高20%,同时工作电压仅为1.1V,低于标准的1.2V。通过采用更新的封装材料和优化的电路设计,使得在高速运行时的发热量降低,GDDR7的热阻比GDDR6降低了70%。