From mboxrd@z Thu Jan 1 00:00:00 1970 Message-ID: To: 9fans@9fans.net From: Richard Miller <9fans@hamnavoe.com> Date: Sat, 14 Nov 2009 09:43:45 +0000 In-Reply-To: <426EC536-0207-47C8-93B9-C16623F895FC@mac.com> MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit Subject: Re: [9fans] rows to cols? Topicbox-Message-UUID: 9bb3de4e-ead5-11e9-9d60-3106f5b1d025 > Wow. > Excellent us of tools. It's the sort of thing I used to give as an exercise to students. > 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 Explicit looping looks so strenuous. To make the tr|pr method more general, you can count columns first with sed 1q | wc -b or if you like awk '{print NF;exit}' Counting rows is left as an exercise to the reader ...