shell字符截取命令之cut命令的實(shí)例詳解
更新時間:2017年09月09日 14:20:36 投稿:lqh
這篇文章主要介紹了shell字符截取命令之cut命令的實(shí)例詳解的相關(guān)資料,希望通過本文大家能夠掌握這部分內(nèi)容,需要的朋友可以參考下
shell字符截取命令之cut命令的實(shí)例詳解
一 語法
cut [選項(xiàng)] 文件名 選項(xiàng): -f 列號:提取第幾列 -d 分隔符:按照指定分隔符分割列
二 實(shí)戰(zhàn)
[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
只能分割比較規(guī)則的文本,一般分割符是制表符或冒號。
不能簡單的用空格作為分割符。
如有疑問請留言或者到本站社區(qū)交流討論,感謝閱讀,希望能幫助到大家,謝謝大家對本站的支持!
相關(guān)文章
linux下安裝配置Memcache和PHP環(huán)境的實(shí)現(xiàn)
下面小編就為大家?guī)硪黄猯inux下安裝配置Memcache和PHP環(huán)境的實(shí)現(xiàn)。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2017-02-02shell 操作釘釘機(jī)器人實(shí)現(xiàn)告警提醒的方法
這篇文章主要介紹了shell 操作釘釘機(jī)器人實(shí)現(xiàn)告警提醒的方法,文中通過示例代碼介紹的非常詳細(xì),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-05-05