Differences between version 28 and revision by previous author of PerlOneLiners.
Other diffs: Previous Major Revision, Previous Revision, or view the Annotated Edit History
Newer page: | version 28 | Last edited on Thursday, August 25, 2005 9:55:14 am | by JohnMcPherson | Revert |
Older page: | version 27 | Last edited on Thursday, August 25, 2005 12:42:44 am | by AristotlePagaltzis | Revert |
@@ -46,8 +46,17 @@
!! Convert data from rows to columns
This assumes that each of the input rows is exactly the same length (in terms of number of items), and assumes they are separated by spaces. This is useful if you have data in tabular form, but need it to be in columns instead (eg. you want to use it as input to GnuPlot).
+<verbatim>
+perl -e '@rows=();
+ while ($l=<>) {@line=split(/ \s+/,$l); push @rows, [@line ]}
+ for $i (0 .. @{$rows[0]}) {
+ for $row (@rows) {print $row->[$i] . "\t"}
+ print "\n"
+ }'
+</verbatim>
+or alternatively:
<verbatim>
perl -F'\s+' -ne'push @rows, [ @F ]; END {
for $i ( 0 .. $#{ $rows[0] } ) {
for $cols ( @rows ) { print $cols->[ $i ] . "\t" }