shell字符截取命令之cut命令的实例详解
shell字符截取命令之cut命令的实例详解
一语法
cut[选项]文件名 选项: -f列号:提取第几列 -d分隔符:按照指定分隔符分割列
二实战
[root@localhost~]#catstudent.txt 1furongF85 2fengjF60 3cangF70 [root@localhost~]#cut-f2student.txt furong fengj cang [root@localhost~]#cut-f2,4student.txt furong85 fengj60 cang70 [root@localhost~]#grep"/bin/bash"/etc/passwd|grep-v"root"|cut-f1-d":" cakin24 test cls [root@localhost~]#cut-d":"-f1,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""-f1,3
只能分割比较规则的文本,一般分割符是制表符或冒号。
不能简单的用空格作为分割符。
如有疑问请留言或者到本站社区交流讨论,感谢阅读,希望能帮助到大家,谢谢大家对本站的支持!