roadtest has asked for the wisdom of the Perl Monks concerning the following question:
Background: Window Excel supports maximum 256 columns or 64K rows. Many of our CSV files were generated with 30~60 rows and 1000~2500 columns. So it can't be fed to excel directly.
I would like to invert row and columns as following:
#!/usr/bin/perl my @data; while (<DATA>) { chomp; push @data,[split /,/]; } for my $z ( 0 .. $#data ) { for my $v ( 0 .. $#{$data[$z]} ) { print "$data[$v][$z],"; } print "\n"; } __DATA__ Date,a,b,c,d,e,f Mon-1,11,12,13,14,15,16 Mon-2,21,22,23,24,25,26 Tue-1,31,,33,34,35,36 Tue-2,41,42,,44,45,46 Wed-1,51,52,53,54,55,56 Wed-2,61,62,63,64,65,66
Everything appears working fine
When I run it against the csv file, it can't convert all columns to row. I am puzzled by the behavior. It may be related to the csv content. Here is a small portion of one csv file
===
,/dir/dir1/file1,/dir/dir1/dir3,/dir/dir1/file2,/dir/dir1/file3,/dir/dir1/dir2,.....(up to 1000-2000 diretory or filename)
May-1,34,44,44,443,68,93,,,,,993,9,2,,,,13343,...(up to 1000-2000 columns)
May-2,343,343,,343,343,,,,4343,5,56,,,,,,........
May-3,3030...
....
May-30....
===
I like to see output like:
Thanks for your comments,May-1,May-2,May-3,May-.......,May-30 /dir/dir1/file1,3,34,,,,34,....... /dir/dir1/dir3,..... /dir/dir1/file2,.... /dir/dir1/file3,... /dir/dir1/dir2.... ..up to 1000-2000 rows..
carl
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Invert CSV
by GrandFather (Saint) on May 30, 2011 at 22:13 UTC | |
by roadtest (Sexton) on May 31, 2011 at 16:42 UTC | |
|
Re: Invert CSV
by BrowserUk (Patriarch) on May 30, 2011 at 19:57 UTC | |
by roadtest (Sexton) on May 31, 2011 at 16:22 UTC | |
|
Re: Invert CSV
by ig (Vicar) on May 30, 2011 at 20:00 UTC | |
by roadtest (Sexton) on May 31, 2011 at 16:27 UTC | |
|
Re: Invert CSV
by rgcosma (Beadle) on May 30, 2011 at 20:10 UTC | |
by JavaFan (Canon) on May 30, 2011 at 20:28 UTC | |
by Gulliver (Monk) on May 31, 2011 at 14:07 UTC | |
by roadtest (Sexton) on May 31, 2011 at 16:30 UTC | |
|
Re: Invert CSV
by Tux (Canon) on May 30, 2011 at 21:56 UTC | |
by roadtest (Sexton) on May 31, 2011 at 16:39 UTC |