Wow.
Excellent us of tools.
The smallest arbitrary-columns answer I could come up with was:
awk '{if(m < NF)m=NF;for(i=1;i<=NF;i++)r[NR, i]=$i}END {for(i=1;i<=m;i+
+){for(j=1;j<=NR;j++)printf "%s ", r[j,i];print ""}}' t
I'm sure there's an insane sed solution out there somewhere for very
small numbers of rows and columns.
D
On 13 Nov 2009, at 08:44, Richard Miller wrote:
Is there an easy way to transpose the text so that rows become
columns, and vice versa? Delimiter is space.
If you know in advance the number of rows & colums, it's easy:
term% cat t
one two three four
five six seven eight
nine ten eleven twelve
term% tr -s ' ' '\xA' <t | pr -t -3 -l4 | tr -s ' ' ' '
one five nine
two six ten
three seven eleven
four eight twelve