linux中取出一组数据中的唯一项、重复项

1、

root@PC1:/home/test# ls
test.txt
root@PC1:/home/test# cat test.txt
1
3
8
1
3
5
1
7
root@PC1:/home/test# sort test.txt | uniq -d    ## 取出重复项
1
3
root@PC1:/home/test# sort test.txt | uniq -u    ## 取出唯一项
5
7
8

 

root@PC1:/home/test# ls
a.txt
root@PC1:/home/test# cat a.txt
1
3
8
1
3
5
1
7
root@PC1:/home/test# sort -u a.txt     ## 去除重复后剩余的所有唯一项
1
3
5
7
8
root@PC1:/home/test# sort a.txt | uniq    ## 同上
1
3
5
7
8

 

posted @ 2022-01-21 15:36  小鲨鱼2018  阅读(207)  评论(0编辑  收藏  举报