cut

cut命令用来显示行中的指定部分,删除文件中的指定字段

 

-b: 仅显示行中指定范围的字节

-c:仅显示行中指定范围的字符;

-d:指定字段的分隔符,默认的字段分隔符为 ”tab”;

-f:显示指定字段的内容

--complement 提取指定字段之外的列

 

以下结合 -b、-c、-f 使用

N-:从第N个字节、字符、字段到结尾;

N-M:从第N个字节、字符、字段到第M个(包括M在内)字节、字符、字段;

-M:从第1个字节、字符、字段到第M个(包括M在内)字节、字符、字段。

 

Eg. echo "tong yi shu" | cut -f2 -d ' '

Output : yi

Eg. echo "tong yi shu" | cut -f2 -d ' ' –complement

Output : tong shu

Eg. echo "tong yi shu" | cut -c1-3

Output : ton

Eg. echo "tong yi shu" | cut -c-9

Output : tong yi s

Eg. echo "tong yi shu" | cut -d ' ' -f2-3

Output : tong yi

原文地址:https://www.cnblogs.com/tongyishu/p/11990802.html