shell字符截取命令之cut命令的實例詳解
一 語法
cut [選項] 文件名選項:-f 列號:提取第幾列-d 分隔符:按照指定分隔符分割列
二 實戰
[root@localhost ~]# cat student.txt1 furong F 852 fengj F 603 cang F 70[root@localhost ~]# cut -f 2 student.txtfurongfengjcang[root@localhost ~]# cut -f 2,4 student.txtfurong 85fengj 60cang 70[root@localhost ~]# grep "/bin/bash" /etc/passwd|grep -v "root"|cut -f 1 -d ":"cakin24testcls[root@localhost ~]# cut -d ":" -f 1,3 /etc/passwdroot:0bin:1daemon:2adm:3lp:4sync:5shutdown:6halt:7mail:8operator:11games:12ftp:14nobody:99systemd-bus-proxy:999systemd-network:998dbus:81polkitd:997abrt:173unbound:996tss:59colord:995usbmuxd:113geoclue:994rpc:32rtkit:172chrony:993radvd:75qemu:107avahi-autoipd:170setroubleshoot:992rpcuser:29nfsnobody:65534saslauth:991libstoragemgmt:990pulse:171gdm:42gnome-initial-setup:989avahi:70sshd:74postfix:89ntp:38tcpdump:72cakin24:1000test:1003cls:1001
三 cut命令的局限
df -h|cut -d " " -f 1,3
只能分割比較規則的文本,一般分割符是制表符或冒號。
不能簡單的用空格作為分割符。
如有疑問請留言或者到本站社區交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
新聞熱點
疑難解答