文本处理命令
sort命令
sort是排序的命令,默认使用第一个字符进行排序
-n # 依照数值的大小排序
[root@localhost ~]# cat 1.txt | sort -n
-r # 以相反的顺序来排序
[root@localhost ~]# cat 1.txt | sort -n -r
-k # 以某列进行排序(默认的分隔符是空格)
[root@localhost ~]# cat 2.txt | sort -n -k2
-t # 指定分割符,默认是以空格为分隔符
[root@localhost ~]# cat 3.txt | sort -n -k2 -t:
uniq 命令
(去重,默认只去重相邻的数据)
一般与 sort 命令结合使用
[root@localhost ~]# cat 1.txt | sort -n | uniq
-c # 在每列旁边显示该行重复出现的次数。
[root@localhost ~]# cat 1.txt | sort -n | uniq -c
-d # 仅显示重复出现的行列。
[root@localhost ~]# cat 1.txt | sort -n | uniq -c -d
-u # 仅显示出一次的行列。
[root@localhost ~]# cat 1.txt | sort -n | uniq -c -u
cut 命令(分割字符)
cut命令用来显示行中的指定部分,删除文件中指定字段。
-d # 指定字段的分隔符,默认的字段分隔符为"TAB"