#!/usr/bin/perl # The Missing Textutils, Ondrej Bojar, obo@cuni.cz # http://www.cuni.cz/~obo/textutils # # 'transpose' swaps rows and columns in the given tab-delimited table. # # $Id: transpose,v 1.2 2005/10/10 07:33:50 bojar Exp $ # while (<>) { chomp; @line = split /\t/; $oldlastcol = $lastcol; $lastcol = $#line if $#line > $lastcol; for (my $i=$oldlastcol; $i < $lastcol; $i++) { $outline[$i] = "\t" x $oldlastcol; } for (my $i=0; $i <=$lastcol; $i++) { $outline[$i] .= "$line[$i]\t" } } for (my $i=0; $i <= $lastcol; $i++) { $outline[$i] =~ s/\s*$//g; print $outline[$i]."\n"; }