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
In reply to Invert CSV by roadtest
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |