#!/usr/bin/perl # Assuming that you have perl, and that you have changed the permissions on this file so that it can be executable ("chmod u+x transpose") # then the usage is: # transpose [filename] # # written by: Jaideep Singh # date: December 05, 2006 # email: singhj AT jlab DOT org # # description: will transpose a tab sepearated file # every row must have the same number of columns! # # for example input: 1 2 # 3 4 # # output: 1 3 # 2 4 # $filename = $ARGV[0]; open(INFILE,"<$filename") or die "error: File - $filename - not found!\n"; $totrow = 0; %data = (); while () { chomp; @parts = split /\t/; for ($ncol = 0 ; $ncol < $#parts+1 ; $ncol++) { $data{$totrow}{$ncol} = $parts[$ncol]; } $totcol = $ncol; $totrow++; } close(INFILE); for ($ncol = 0 ; $ncol < $totcol ; $ncol++) { for ($nrow = 0 ; $nrow < $totrow ; $nrow++) { print "$data{$nrow}{$ncol}"; if ($nrow < $totrow-1) { print "\t"; } else { print "\n"; } } }