文件去重

1. 文件去重

sort file |uniq

sort -n file |uniq 

2. 文件按某一列去重

# 按照第二列去重
root@solitude[20:28:32]$ cat file 
beijing::198
shanghai::87
shenzhen::87
beijing::100
shanghai::198
shanghai::107
shenzhen::198
shanghai::100
root@solitude[20:28:33]$ awk -F "::" '!dup[$2]++' file 
beijing::198
shanghai::87
beijing::100
shanghai::107
root@solitude[20:29:09]$ awk -F "::" '!($2 in dup){dup[$2]; print $0}' file 
beijing::198
shanghai::87
beijing::100
shanghai::107
root@solitude[20:29:28]$ sort -t ":" -k 3,3 -u file 
beijing::100
shanghai::107
beijing::198
shanghai::87
root@solitude[20:29:36]$ 

awk 速度快于 sort

 

posted @ 2020-02-10 20:35  lixin[at]hitwh  阅读(379)  评论(0编辑  收藏  举报