From mboxrd@z Thu Jan 1 00:00:00 1970 MIME-Version: 1.0 In-Reply-To: <18087f99b33ebe5fbec227e86218045e@hamnavoe.com> References: <18087f99b33ebe5fbec227e86218045e@hamnavoe.com> Date: Fri, 13 Nov 2009 01:36:43 -0800 Message-ID: From: Tharaneedharan Vilwanathan To: Fans of the OS Plan 9 from Bell Labs <9fans@9fans.net> Content-Type: multipart/mixed; boundary=000e0cd32ed6d7d6fe04783d657d Subject: Re: [9fans] rows to cols? Topicbox-Message-UUID: 9a778da0-ead5-11e9-9d60-3106f5b1d025 --000e0cd32ed6d7d6fe04783d657d Content-Type: multipart/alternative; boundary=000e0cd32ed6d7d6f904783d657b --000e0cd32ed6d7d6f904783d657b Content-Type: text/plain; charset=ISO-8859-1 hi, i rustled up a small limbo program (attached) that does the trick. hope this helps. % cat num1.txt one two three four five six seven eight nine % ./trans num1.txt one four seven two five eight three six nine % cat num2.txt one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen % ./trans num2.txt one five eight ten eleven thirteen sixteen two six nine ---- twelve fourteen seventeen three seven ---- ---- ---- fifteen eighteen four ---- ---- ---- ---- ---- nineteen % thanks dharani On Fri, Nov 13, 2009 at 12:44 AM, Richard Miller <9fans@hamnavoe.com> 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 > > --000e0cd32ed6d7d6f904783d657b Content-Type: text/html; charset=ISO-8859-1 Content-Transfer-Encoding: quoted-printable
hi,
=A0
i=A0rustled up a small limbo program (attac= hed) that does the trick.
=A0
hope this helps.
=A0
% cat num1.txt
one two three
four five six
seven eight nine
% ./trans num1.txt
=A0 =A0 =A0one =A0 =A0 =A0four = =A0 =A0 seven
=A0 =A0 =A0two =A0 =A0 =A0five = =A0 =A0 eight
=A0 =A0three =A0 =A0 =A0 six =A0 = =A0 =A0nine
% cat num2.txt
one two three four
five six seven
eight nine
ten
eleven twelve
thirteen fourteen fifteen<= /div>
sixteen seventeen eighteen ninete= en
% ./trans num2.txt
=A0 =A0 =A0one =A0 =A0 =A0five = =A0 =A0 eight =A0 =A0 =A0 ten =A0 =A0eleven =A0thirteen =A0 sixteen =
=A0 =A0 =A0two =A0 =A0 =A0 six = =A0 =A0 =A0nine =A0 =A0 =A0---- =A0 =A0twelve =A0fourteen seventeen =
=A0 =A0three =A0 =A0 seven =A0 = =A0 =A0---- =A0 =A0 =A0---- =A0 =A0 =A0---- =A0 fifteen =A0eighteen =
=A0 =A0 four =A0 =A0 =A0---- =A0 = =A0 =A0---- =A0 =A0 =A0---- =A0 =A0 =A0---- =A0 =A0 =A0---- =A0nineteen
%
=A0
thanks
dharani=A0
=A0
On Fri, Nov 13, 2009 at 12:44 AM, Richard Miller <9fans@hamnavoe.com> wrote:
>
> > Is there an easy way to transpose the text so that rows beco= me
> > 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% =A0tr -s ' ' '\xA' <t | pr -t -3 -l4 | t= r -s ' ' ' '
> one five nine
> two six ten
> three seven eleven
> four eight twelve
>
>
=A0
=A0
--000e0cd32ed6d7d6f904783d657b-- --000e0cd32ed6d7d6fe04783d657d Content-Type: application/octet-stream; name="trans.b" Content-Disposition: attachment; filename="trans.b" Content-Transfer-Encoding: base64 X-Attachment-Id: f_g1yr4vwl0 aW1wbGVtZW50IFRyYW5zOwoKaW5jbHVkZSAic3lzLm0iOwoJc3lzOiBTeXM7CgppbmNsdWRlICJk cmF3Lm0iOwppbmNsdWRlICJidWZpby5tIjsKCk1heExpc3QgOiBjb24gNTAwOwoKVHJhbnM6IG1v ZHVsZQp7Cglpbml0OglmbihuaWw6IHJlZiBEcmF3LT5Db250ZXh0LCBhcmdzOiBsaXN0IG9mIHN0 cmluZyk7Cn07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