gilou Modérateur Modzilla | Un truc pondu vite fait, en perl:
Code :
#!/usr/bin/perl use strict; use warnings; use autodie; my @lines; my $input = 'mycsv.txt'; my $ouput1 = 'out1.txt'; my $ouput2 = 'out2.txt'; open my $fh, "<", $input; while (<$fh> ) { next if ($. <2); my ($entreprise, $address, $code, %cmd) = split /;|\n/; push @lines, [$entreprise, $address, $code, $cmd{RV34 }, $cmd{RV56 }]; } print $fh "Entreprise;Adresse;Code_E;Commande;Qte;Commande;Qte\n"; foreach (@lines) { print $fh "$_->[0];$_->[1];$_->[2];RV34;$_->[3];RV56;$_->[4]\n"; } print $fh "Entreprise;Adresse;Code_E;Commande;\n"; foreach (@lines) { print $fh "$_->[0];$_->[1];$_->[2];RV34;$_->[3]\n"; print $fh "$_->[0];$_->[1];$_->[2];RV56;$_->[4]\n"; }
|
et une variante, un peu plus verbeuse et explicite:
Code :
#!/usr/bin/perl use strict; use warnings; use autodie; my @lines; my $input = 'mycsv.txt'; my $ouput1 = 'out1.txt'; my $ouput2 = 'out2.txt'; open my $fh, "<", $input; while (<$fh> ) { next if ($. <2); my ($entreprise, $address, $code, %cmd) = split /;|\n/; push @lines, {Entreprise => $entreprise, Addresse => $address, Code => $code, RV34 => $cmd{RV34 }, RV56 => $cmd{RV56 }}; } print $fh "Entreprise;Adresse;Code_E;Commande;Qte;Commande;Qte\n"; foreach (@lines) { print $fh "$_->{Entreprise};$_->{Addresse};$_->{Code};RV34;$_->{RV34};RV56;$_->{RV56}\n"; } print $fh "Entreprise;Adresse;Code_E;Commande;\n"; foreach (@lines) { print $fh "$_->{Entreprise};$_->{Addresse};$_->{Code};RV34;$_->{RV34}\n"; print $fh "$_->{Entreprise};$_->{Addresse};$_->{Code};RV56;$_->{RV56}\n"; }
|
A+, Message édité par gilou le 23-04-2015 à 22:29:34 ---------------
There's more than what can be linked! -- Iyashikei Anime Forever! -- AngularJS c'est un framework d'engulé! --
|