假设有个文件hello.txt
[root@liuzhiwei-centos6 ~]# cat hello.txt
hello world welcome
hello world
world welcome
hello welcome
hello world
hello world welcome
world world heihei
welcome hello
hello world
world heihei
hello welcome
world welcome
(1)sort、uniq统计文本行数、相同行数量
统计行数:
[root@liuzhiwei-centos6 ~]# cat hello.txt | wc -l
12
统计每个相同行的数量:
[root@liuzhiwei-centos6 ~]# cat hello.txt | sort | uniq -c
2 hello welcome
3 hello world
2 hello world welcome
1 welcome hello
1 world heihei
2 world welcome
1 world world heihei
根据行数进行排序:
[root@liuzhiwei-centos6 ~]# cat hello.txt | sort | uniq -c | sort -n
1 welcome hello
1 world heihei
1 world world heihei
2 hello welcome
2 hello world welcome
2 world welcome
3 hello world
(2