From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-version: 1.0 Content-transfer-encoding: 7BIT Content-type: text/plain; charset=US-ASCII; format=flowed; delsp=yes Message-id: <426EC536-0207-47C8-93B9-C16623F895FC@mac.com> From: dave.l@mac.com To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> In-reply-to: <18087f99b33ebe5fbec227e86218045e@hamnavoe.com> Date: Fri, 13 Nov 2009 23:53:21 +0000 References: <18087f99b33ebe5fbec227e86218045e@hamnavoe.com> Subject: Re: [9fans] rows to cols? Topicbox-Message-UUID: 9b8ac6d0-ead5-11e9-9d60-3106f5b1d025 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' one five nine > two six ten > three seven eleven > four eight twelve > >