linux中awk实现类sort -u命令

 

1、测试数据

[root@centos7 test4]# ls
test.txt
[root@centos7 test4]# cat test.txt
3
2
7
3
2
8
7
[root@centos7 test4]# sort -u test.txt   ## sort -u命令
2
3
7
8

 

2、awk实现类sort -u命令

[root@centos7 test4]# ls
test.txt
[root@centos7 test4]# cat test.txt
3
2
7
3
2
8
7
[root@centos7 test4]# awk '!x[$0]++' test.txt   ##不在数组内的元素进行添加,最后输出
3
2
7
8

 

posted @ 2022-04-14 14:59  小鲨鱼2018  阅读(170)  评论(0编辑  收藏  举报