in reply to AWK? Split one file in seperate files based on country
I used UTF-8 encoding for the accented characters. You might need to change the encoding if your input file uses a different one.#!/usr/bin/perl use strict; use warnings; my %countries; open my $IN, '<:encoding(utf-8)', '1.csv' or die $!; while (<$IN>) { my @columns = split /;/; push @{ $countries{$columns[0]} }, $_; } for my $country (keys %countries) { open my $OUT, '>:encoding(utf-8)', "$country.csv" or die $!; for (@{ $countries{$country} }) { print {$OUT} $_; } close $OUT or die $!; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: AWK? Split one file in seperate files based on country
by Janwhatever (Novice) on May 31, 2012 at 08:28 UTC | |
by choroba (Cardinal) on May 31, 2012 at 08:41 UTC | |
by Janwhatever (Novice) on May 31, 2012 at 09:02 UTC | |
by choroba (Cardinal) on May 31, 2012 at 09:11 UTC | |
by Janwhatever (Novice) on May 31, 2012 at 13:57 UTC | |
|