Viktor Rosenfeld wrote: > > Hi list, > > this one is for all the regexp, shell, and editing-experts...
How about us perl hackers, hunh?! Got sumpin' g'inst us, buddy!? > Suppose I have a comma-seperated or tab-seperated file and I want > to flip the lines and columns. So an input file like: > > a,1,A > b,2,B > c,3,C > > would be transformed into: > > a,b,c > 1,2,3 > A,B,C > > Is there an fast and easy way of doing this? Ideally through the shell > or with VIM. I would RTFM, but I have no clue which manual to read. Well, you could use regexp in sed, or use an awk script, but if I had only 3x3 matrices to transform, in text, I'd perl -e 'for ($i=0;$i<3;++$i){<>;@entry = split ',';print "$i[0],$i[1],$i[2]\n";}' with a file directed into it, and stdout redirected to a file. Matrixes with unpredetermined columns or rows become slightly trickier, but only by 1) keeping track of the length/breadth, and 2) nesting another loop. > > TIA, YWATF (You're Welcome After The Fact)