# Transpose text as if it were a matrix of characters. # e.g. abc becomes ad # def be # cf BEGIN { numlines = 0; maxlinelen = 0; lineout = ""; } { line[NR] = $0; if ( maxlinelen < length( $0 ) ) maxlinelen = length( $0 ); numlines = NR; } END { for ( i = 1; i <= maxlinelen; i++ ) { for ( j = 1; j <= numlines; j++ ) { lineout = lineout substr( line[j], i, 1 ); } print lineout; lineout = ""; } }