P:\test>type t1.csv 1,the,rest 2,the,rest 3,the,rest 4,the,rest 5,the,rest P:\test>type t2.csv 2,the,rest 4,the,rest 6,the,rest 8,the,rest #### # 23456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 123456789 1234 perl -anF, -le"$h{$F[0]}=1;eof&&last}{$h{(split',',$_)[0]}--while<>;$h{$_}&&print $h{$_}<0?'1:':'2:',$_ for keys%h" t1.csv t2.csv 1:8 1:6 2:1 2:3 2:5