Linux 中实现去重复后仍然按照原来的顺序输出

 

001、一般去重复

[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt                       ## 测试文本
c
d
c
a
b
b
[root@PC1 test01]# cat a.txt | sort | uniq         ## 去重复后也排序了
a
b
c
d

 

002、去重复后保持原来的顺序

[root@PC1 test01]# ls
a.txt
[root@PC1 test01]# cat a.txt                         ## 测试文本
c
d
c
a
b
b
[root@PC1 test01]# awk '!ay[$0]++' a.txt             ## 去重复后保持原来的顺序
c
d
a
b

 。

 

posted @ 2024-02-06 10:41  小鲨鱼2018  阅读(15)  评论(0编辑  收藏  举报