linux常用命令 cut字符截取命令


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


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM