1、cut
cut的工作就是“剪”,具体的说就是在文件中负责剪切数据用的,cut命令从文件的每一行剪切字节,字符和字段输出。
(1)基本语法:cut [选项参数] filename
说明:默认分隔符是制表符
(2)选项参数说明
选项参数 | 功能 |
-f | 列号,提取第几列 |
-d | 分隔符,按照指定分隔符分割列,默认是制表符“\t” |
-c |
按字符进行切割后加n表示取第几列 比如-c 1 |
(3)案例实操
①数据准备
[root@hadhoop100 scripts]# touch cut.txt
[root@hadhoop100 scripts]# vim cut.txt
在cut.txt中输入
dong shen
guan zhen
wo wo
lai lai
le le
②切割cut.txt第一列
[root@hadhoop100 scripts]# cut -d " " -f 1 cut.txt #先对cut.txt的内容用空格分割,然后取第1列
dong
guan
wo
lai
le
③切割cut.txt第二、三列
[root@hadhoop100 scripts]# cut -d " " -f 2,3 cut.txt
shen
zhen
wo
lai