Linux common command cut character interception command

cut character interception

cut [options] filename

选项
-f 列号: 提取第几列
-d 分割符:按照指定的分隔符分割列

Tabs ("tab") are used for splitting by default

ssgao:Downloads aouo$ cut -f 2 ssgao.txt  获取第列
ssgao
ssgao:Downloads aouo$ cut -f 2,4 ssgao.txt 获取第4列
ssgao   37

Use custom delimiter

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$ 

Disadvantages of cut command

很复杂的分割,比如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

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=324646081&siteId=291194637