代码之家  ›  专栏  ›  技术社区  ›  kawther

从csv文件中的列获取唯一值[重复]

  •  1
  • kawther  · 技术社区  · 7 年前

    我有以下输入:

    no,zadrar,MENTOR,rossana@xt.com,AGRATE
    no,mittalsu,MENTOR,rossana@xt.com,GREATER NOIDA
    no,abousamr,CADENCE,selim@xt.com,CROLLES
    no,lokinsks,MENTOR,sergey@xt.com,CROLLES
    no,billys,MENTOR,billy@xt.com,CROLLES
    no,basiles1,CADENCE,stephane@xt.com,CASTELLETTO
    no,cesaris1,CADENCE,stephane@xt.com,CROLLES
    

    no,abousamr,CADENCE,selim@xt.com,CROLLES
    no,lokinsks,MENTOR,sergey@xt.com,CROLLES
    no,billys,MENTOR,billy@xt.com,CROLLES
    

    我试过:

    awk -F"," '{print $4}' $vendor.csv | sort | uniq -u
    

        selim@xt.com
        sergey@xt.com
        billy@xt.com
    
    2 回复  |  直到 7 年前
        1
  •  2
  •   RavinderSingh13 Nikita Bakshi    7 年前

    请尝试以下操作(读取输入文件2次)。

    awk -F',' 'FNR==NR{a[$4]++;next} a[$4]==1'  Input_file Input_file
    
        2
  •  2
  •   elcortegano    7 年前

    您只需使用 sort 命令:

    sort -u -t, -k4,4 file.csv
    

    man 页面,选项 -u -t 对于字段分隔符,以及 -k 允许您选择位置(键)。