awk + How do I find duplicates in a column?

后端 未结 1 1332
无人共我
无人共我 2021-02-09 09:14

How do I find duplicates in a column?

$ head countries_lat_long_int_code3.csv | cat -n
     1  country,latitude,longitude,name,code
     2  AD,42.546245,1.601554         


        
1条回答
  •  暖寄归人
    2021-02-09 09:54

    This will give you the duplicated codes

    awk -F, 'a[$5]++{print $5}'
    

    if you're only interested in count of duplicate codes

    awk -F, 'a[$5]++{count++} END{print count}'
    

    To print duplicated rows try this

    awk -F, '$5 in a{print a[$5]; print} {a[$5]=$0}'
    

    This will print the whole row with duplicates found in col $5:

    awk -F, 'a[$5]++{print $0}'
    

    0 讨论(0)
提交回复
热议问题