I have a file that has the following format:
487422,Potenza
487386,Forlì-Cesena
487399,Grosseto
487425,Catanzaro
487409,Napoli
487446,Prato
495498,Fermo
487425,Catanzaro
487389,Macerata
487442,Biella
487351,Asti
487424,Cosenza
487404,Roma
487359,Como
487404,Roma
487401,Terni
487420,Brindisi
487397,Arezzo
487348,Vercelli
487382,Modena
487356,Genova
487365,Cremona
487369,Verona
487386,Forlì-Cesena
As you can see, it is a comma-separated text with duplicates. I would like to deduplicate the text with respect to column 1 using awk.
Command line
If I use the shell interface, this is what I get
487422,Potenza
487386,Forlì-Cesena
487399,Grosseto
487425,Catanzaro
487409,Napoli
487446,Prato
495498,Fermo
487389,Macerata
487442,Biella
487351,Asti
487424,Cosenza
487404,Roma
487359,Como
487401,Terni
487420,Brindisi
487397,Arezzo
487348,Vercelli
487382,Modena
487356,Genova
487365,Cremona
487369,Verona
which is what I would expect from the following command
awk -F"," '!a[$1]++' filename.csv
Awk script
If I use the awk script written as follows
#!/bin/awk -f
BEGIN {
FS=","
}
{
{!a[$1]++}
}
I do not get any output. Is there something wrong with the script? Why is the behaviour different between the script and the command line?