in reply to AWK? Split one file in seperate files based on country

A one liner:

perl -F; -anle"$F[0] ne $last and open F, '>', $F[0].'.csv'; print F; +$last = $F[0]" junk.dat C:\test>dir *.csv 30/05/2012 23:17 204 Albani‰.csv 30/05/2012 23:17 194 Andorra.csv 30/05/2012 23:17 325 Belgi‰.csv 30/05/2012 23:17 394 Engeland.csv 30/05/2012 23:17 295 Finland.csv 30/05/2012 23:17 332 Frankrijk.csv C:\test>type Albani‰.csv Albanië;Albanië;Berat;Hotel;Berati;40,9999;19,99999;Meer;ok;0; Albanië;Albanië;Berat;Hotel;Castle Park;45,769969;19,9999;Meer;ok;0; Albanië;Albanië;Berat;Hotel;Mangalemi;40,709999;19,959999;Meer;ok;0; C:\test>type Andorra.csv Andorra;Andorra;El Serrat;Hotel;Subi;43,658607;5,568623;;ok;0; Andorra;Andorra;El Serrat;Hotel;Tristan;42,618507;1,538923;;ok;0; Andorra;Andorra;El Tarter;Hotel;Del;42,580340;1,648919;;ok;0; C:\test>type Belgi‰.csv België;Antwerpen;Antwerpen;Bezienswaardigheid;Boerentoren (Kbc Toren); +51,2000;4,399000;;ok;0; België;Antwerpen;Antwerpen;Bed&Breakfast;Borze;51,2200;4,399000;;ok;0; België;Antwerpen;Antwerpen;Bed&Breakfast;Boulevard ;51,220000;4,399000 +;;ok;0; België;Antwerpen;Antwerpen;Appartement;Britselei 37;51,220000;4,399000 +;;ok;0;

With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.

The start of some sanity?

Replies are listed 'Best First'.
Re^2: AWK? Split one file in seperate files based on country
by jwkrahn (Abbot) on May 31, 2012 at 01:58 UTC
    perl -F';' -ane'open F, ">>$F[0].csv" and print F' junk.dat

      Nice golfing :)

      You'd have to remember to delete the output files before a re-run; and if the input is big, reopening the output files would likely be a significant factor.

      I kept thinking about the one-arg open, but I couldn't make it work with an array element.


      With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

      The start of some sanity?

        I kept thinking about the one-arg open, but I couldn't make it work with an array element.
        perl -F';' -ane'$F = ">>$F[0].csv"; open F and print F' junk.dat