首頁  >  文章  >  運維  >  實例分享shell字元截取指令之cut指令

實例分享shell字元截取指令之cut指令

巴扎黑
巴扎黑原創
2017-09-11 11:15:032170瀏覽

這篇文章主要介紹了shell字元截取命令之cut命令的實例詳解的相關資料,希望透過本文大家能夠掌握這部分內容,需要的朋友可以參考下

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指令的詳細內容。更多資訊請關注PHP中文網其他相關文章!

陳述:
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn