Xref: utzoo alt.sources.wanted:6 comp.sources.wanted:9346 comp.unix.questions:17544 Path: utzoo!utgpu!jarvis.csri.toronto.edu!mailrus!iuvax!purdue!bu-cs!xylogics!world!bzs From: bzs@world.std.com (Barry Shein) Newsgroups: alt.sources.wanted,comp.sources.wanted,comp.unix.questions Subject: Re: matrix invert routine Message-ID: <1989Nov9.233341.14788@world.std.com> Date: 9 Nov 89 23:33:41 GMT References: <1612@xn.LL.MIT.EDU> Organization: The World @ Software Tool & Die Lines: 43 >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 I'm too lazy to do all the work but here's the basic attack, it can easily be done in a shell loop: Assume you have 3 columns as shown: #!/bin/sh cp /dev/null outfile for i in 1 2 3 do cut -f$i datafile | tr '\012' '\011' >> outfile echo '' >> outfile end ed - outfile <<'EOF' 1,$s/.$// w q EOF Explanation: "cut" cuts vertical fields separated by tabs (or a specified character, see man page), the rest is pretty easy. "Tr" replaces all the newlines with tabs thus flattening the column you cut into a row, the echo puts a newline on the end of each line. The ed script fixes the fact that you ended up with an extra tab on each line (the very last newline got changed to a tab.) There's probably some other way to do this (avoiding the final ed script) but this will certainly work and I think that's what you were after. -- -Barry Shein Software Tool & Die, Purveyors to the Trade | bzs@world.std.com 1330 Beacon St, Brookline, MA 02146, (617) 739-0202 | {xylogics,uunet}world!bzs