1. sort 命令对文件的行进行排序
使用的命令如下:sort testfile
sort 命令将以默认的方式将文本文件的第一列以ASCII 码的次序排列,并将结果输出到标准输出。
$ cat test1 # test1文件原有排序
test
test
test
hello
world
world
hello
hello
$ sort test1 #排序结果
hello
hello
hello
test
test
test
world
world
2. uniq 命令删除连续重复出现的行
uniq testfile
删除连续重复出现的行
$ uniq test1
test
hello
world
hello
$ uniq -c test1 # -c或--count 在每列旁边显示该行重复出现的次数。
3 test
1 hello
2 world
2 hello
3. sort -u 排序后删除重复行
先sort,再用uniq可以实现sort -u
sort -u test1
等价于sort test1 | uniq
$ sort -u test1 #sort -u是全局的。
hello
test
world