Xref: utzoo alt.sources.wanted:9 comp.sources.wanted:9363 comp.unix.questions:17574 Path: utzoo!utgpu!utstat!jarvis.csri.toronto.edu!rutgers!tut.cis.ohio-state.edu!ucsd!ogccse!emory!arnold From: arnold@mathcs.emory.edu (Arnold D. Robbins {EUCC}) Newsgroups: alt.sources.wanted,comp.sources.wanted,comp.unix.questions Subject: Re: matrix invert routine Message-ID: <4573@emory.mathcs.emory.edu> Date: 10 Nov 89 18:19:25 GMT References: <1612@xn.LL.MIT.EDU> <2560@ucsfcca.ucsf.edu> Reply-To: arnold@emory.UUCP (Arnold D. Robbins {EUCC}) Followup-To: alt.sources.wanted Organization: Math and Computer Science, Emory University, Atlanta GA Lines: 60 >In article <1612@xn.LL.MIT.EDU>, rkc@XN.LL.MIT.EDU (rkc) writes: >> I have "spreadsheet-like" data that looks like this: >> a1 b1 c1 >> a2 b2 c2 >> a3 b3 c3 >> and I want to get it in a form like: >> a1 a2 a3 >> b1 b2 b3 >> c1 c2 c3 In article <2560@ucsfcca.ucsf.edu> root@cca.ucsf.edu (Systems Staff) writes: >the transpose with standard Unix tools (I would look at awk first) .... Aha! No sooner said than done. From the 2.11 gawk.texinfo manual: -- Begin Quote -- The following example treats its input as a two-dimensional array of fields; it rotates this array 90 degrees clockwise and prints the result. It assumes that all lines have the same number of elements. awk '{ if (max_nf < NF) max_nf = NF max_nr = NR for (x = 1; x <= NF; x++) vector[x, NR] = $x } END { for (x = 1; x <= max_nf; x++) { for (y = max_nr; y >= 1; --y) printf("%s ", vector[x, y]) printf("\n") } }' When given the input: 1 2 3 4 5 6 2 3 4 5 6 1 3 4 5 6 1 2 4 5 6 1 2 3 it produces: 4 3 2 1 5 4 3 2 6 5 4 3 1 6 5 4 2 1 6 5 3 2 1 6 -- End Quote -- -- Arnold Robbins -- Emory U. Information Technology Div. | Laundry increases DOMAIN: arnold@emoryu1.cc.emory.edu | exponentially in the UUCP: gatech!emoryu1!arnold PHONE: +1 404 727-7636 | number of children. BITNET: arnold@emoryu1 FAX: +1 404 727-2599 | -- Miriam Hartholz