cut 字符截取
cut [選項] 文件名
選項
-f 列號: 提取第幾列
-d 分割符:按照指定的分隔符分割列
默認使用制表符("tab")進行分割
ssgao:Downloads aouo$ cut -f 2 ssgao.txt 獲取第列
ssgao
ssgao:Downloads aouo$ cut -f 2,4 ssgao.txt 獲取第4列
ssgao 37
使用自定義的分割符
ssgao:Downloads aouo$ cat ssgao.txt
name,ssgao,age,37
ssgao:Downloads aouo$ cut -f 1 -d "," ssgao.txt #使用","進行分割,並獲取第一列,-f和-d的前后順序可以互換
name
ssgao:Downloads aouo$
cut命令的缺點
很復雜的分割,比如df -h 輸出的的時候有多個空格
ssgao:Downloads aouo$ df -h
Filesystem Size Used Avail Capacity iused ifree %iused Mounted on
/dev/disk1 233Gi 80Gi 153Gi 35% 1054436 4293912843 0% /
devfs 182Ki 182Ki 0Bi 100% 631 0 100% /dev
map -hosts 0Bi 0Bi 0Bi 100% 0 0 100% /net
map auto_home 0Bi 0Bi 0Bi 100% 0 0 100% /home