显示某一行中某一列中重复值的特定字段

显示某一行中某一列中重复值的特定字段

我/我-

1234505403650,1234505403650,1,XYZ,0,,
1234525941210,1234525941210,1,XYZ,0,,
1234505577168,1234505577168,1,XYZ,0,,
1234518552859,1234518552859,1,XYZ,0,,
1234518552859,1234518552859,1,RTB,0,20200818153307,20200819153307
1234513321215,1234513321215,1,XYZ,0,,
1234523098739,1234523098739,1,XYZ,0,,
1234500964747,1234500964747,1,XYZ,0,,
1234500964747,1234500964747,1,ABC,0,,

预期收益 -

1234518552859,XYZ,RTB
1234500964747,XYZ,ABC

需要从第一个字段中识别重复条目,并<duplicate entry>,<field 4>从与重复条目匹配的所有行中显示

答案1

您可以使用awk

$ awk -F, '
    BEGIN {OFS=FS} 
    {a[$1] = a[$1] == "" ? $4 : a[$1]","$4; c[$1]++} 
    END {for(i in a){if (c[i]>1) print i,a[i]}}
' file
1234518552859,XYZ,RTB
1234500964747,XYZ,ABC

相关内容