Hi there! I'm new to perl and new to perlmonks and hoping to find answers here:) I have a large file which i need to split up into multiple files. There is a condition, the file has to be split up according to country ($elements1). The file is a CSV file and is separated by semicolon like so:
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; 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; 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; Engeland;Groot Londen;Londen;Museum;Tate Britain;51,5200;-0,126236;;ok +;0; Engeland;Groot Londen;Londen;Museum;Tate Modern;51,500200;-0,126236;;o +k;0; Engeland;Groot Londen;Londen;Hotel;Testing;51,500200;-0,126236;;ok;0; Engeland;Groot Londen;Londen;Bezienswaardigheid;Thames (rivier);51,020 +0;-0,126236;;ok;0; Engeland;Groot Londen;Londen;Hotel;The Archery London;51,500200;-0,126 +236;;ok;0; Finland;Finland;Ylläsjärvi;Hotel;Yllasrinne;67,526750;24,275630;;ok;0; Finland;Finland;Ypäjä;Bezienswaardigheid;Loimijoki Golf;0,805300;23,27 +1400;;ok;0 Finland;Finland;Ytteresse;Vakantiepark;Solhaga;0,630700;22,962500;;ok; +0 Finland;Lapland;Hetta;Hotel;Hetan Majatalo;6,34700;23,633800;;ok;0 Frankrijk;Alsace (Elzas);Rouffach;Hotel;Au Relais D'Alsace;7,959680;7, +29970;;ok;0 Frankrijk;Alsace (Elzas);Rouffach;Hotel;Château d Isenbourg;7,959680;7 +,29970;;ok;0 Frankrijk;Alsace (Elzas);Ruederbach;Vakantiehuis;Au Cheval Blanc;47,56 +1440;7,26840;;ok;0 Frankrijk;Alsace (Elzas);Sausheim;Camping;Le fary;4,787300;7,36390;;ok +;0;
And i want it to arrange it like this:
OUTFILE: 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; OUTFILE: 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; OUTFILE: 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; OUTFILE: Engeland.csv Engeland;Groot Londen;Londen;Museum;Tate Britain;51,5200;-0,126236;;ok +;0; Engeland;Groot Londen;Londen;Museum;Tate Modern;51,500200;-0,126236;;o +k;0; Engeland;Groot Londen;Londen;Hotel;Testing;51,500200;-0,126236;;ok;0; Engeland;Groot Londen;Londen;Bezienswaardigheid;Thames (rivier);51,020 +0;-0,126236;;ok;0; Engeland;Groot Londen;Londen;Hotel;The Archery London;51,500200;-0,126 +236;;ok;0; OUTFILE: Finland.csv Finland;Finland;Ylläsjärvi;Hotel;Yllasrinne;67,526750;24,275630;;ok;0; Finland;Finland;Ypäjä;Bezienswaardigheid;Loimijoki Golf;0,805300;23,27 +1400;;ok;0 Finland;Finland;Ytteresse;Vakantiepark;Solhaga;0,630700;22,962500;;ok; +0 Finland;Lapland;Hetta;Hotel;Hetan Majatalo;6,34700;23,633800;;ok;0 OUTFILE: Frankrijk.csv Frankrijk;Alsace (Elzas);Rouffach;Hotel;Au Relais D'Alsace;7,959680;7, +29970;;ok;0 Frankrijk;Alsace (Elzas);Rouffach;Hotel;Château d Isenbourg;7,959680;7 +,29970;;ok;0 Frankrijk;Alsace (Elzas);Ruederbach;Vakantiehuis;Au Cheval Blanc;47,56 +1440;7,26840;;ok;0 Frankrijk;Alsace (Elzas);Sausheim;Camping;Le fary;4,787300;7,36390;;ok +;0;
These are just a few countries in the file, there are many more but this is the general idea. I split the file with @elements = split(/;/,$infile[$i]); but from there i don't know how to procede exactly. I found these topics where somebody is trying a similar thing but with digits. Where as i'm trying it with letters (the countries). Can someone point me in the right direction? with AWK? These look similar as to what i want to accomplish:

http://www.unix.com/shell-programming-scripting/167923-how-split-data-file-into-separate-files-file-names-depending-upon-columns-value.html

http://www.unix.com/shell-programming-scripting/60351-split-file-into-multiple-files-depending-upon-first-4-digits.html


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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.