1、测试数据
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt ## 测试数据 a g b d a b b d c b
2、统计重复项
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt a g b d a b b d c b root@ubuntu01:/home/test# sort a.txt | uniq -d ## 重复项 a b d root@ubuntu01:/home/test# sort a.txt | uniq -D ## 重复项 a a b b b b d d
3、去重复
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt a g b d a b b d c b root@ubuntu01:/home/test# sort -u a.txt ## 去重复 a b c d g root@ubuntu01:/home/test# sort a.txt | uniq ## 去重复 a b c d g
4、取唯一项
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt a g b d a b b d c b root@ubuntu01:/home/test# sort a.txt | uniq -u ## 取唯一项 c g
5、统计重复次数
root@ubuntu01:/home/test# ls a.txt root@ubuntu01:/home/test# cat a.txt a g b d a b b d c b root@ubuntu01:/home/test# sort a.txt | uniq -c ## 统计重复次数 2 a 4 b 1 c 2 d 1 g root@ubuntu01:/home/test# sort a.txt | uniq -c | sed 's/^[\t ]*//g' ## 统计重复次数 2 a 4 b 1 c 2 d 1 g
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。