虚位以待(AD)
虚位以待(AD)
首页 > 脚本专栏 > linux shell > shell字符截取命令之cut命令的实例详解

shell字符截取命令之cut命令的实例详解
类别:linux shell   作者:码皇   来源:互联网   点击:

这篇文章主要介绍了shell字符截取命令之cut命令的实例详解的相关资料,希望通过本文大家能够掌握这部分内容,需要的朋友可以参考下

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

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

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

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

相关热词搜索: shell cut shell cut字符串的详解 shell c