print unique lines based on field

You put your test for “seen” in the action part of the script instead of the condition part. Change it to:

awk -F, '!seen[$1]++' Input.csv

Yes, that’s the whole script:

$ cat Input.csv
10,15-10-2014,abc
20,12-10-2014,bcd
10,09-10-2014,def
40,06-10-2014,ghi
10,15-10-2014,abc
$
$ awk -F, '!seen[$1]++' Input.csv
10,15-10-2014,abc
20,12-10-2014,bcd
40,06-10-2014,ghi

Leave a Comment