> i haven't found avl to be slow, so i was interested in
> this.
It was slow in relation to other methods available. That code wasn't
written to be fast. It came out of a long ago Sunday afternoon
discussion I had with someone about data structures, from which we
ended up cobbling together a few
> It's dog slow (actually, avl(2) is), but its effectively
> unbounded for the input dataset size.
i haven't found avl to be slow, so i was interested in
this. after stripping out the tmp file and the
unnecessary runes, prof tells me this for a
2000x1 array. (normal runtime ~20s)
minooka; p
It's the sort of thing I used to give as an exercise to students.
Wish I'd been in your class.
Explicit looping looks so strenuous.
I know: I kept thinking "map ... join": too much perl.
To make the tr|pr method more general, you can count columns first
with
But that's multi-pass:-).
Y
> 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
> Is there an easy way to transpose the text so that rows become
> columns, and vice versa? Delimiter is space. Perhaps in AWK?
If Richard's trick won't work, grab contrib/lyndon/transpose.c.
It's dog slow (actually, avl(2) is), but its effectively
unbounded for the input dataset size.
--lyndon
Wow.
Excellent us of tools.
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
I'm sure there's an insane sed solution out there somewhere for very
sma
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
> 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'
Hi, folks!
Is there an easy way to transpose the text so that rows become
columns, and vice versa? Delimiter is space. Perhaps in AWK?
Thanks,
=
Petr A. Cejchan
http://home.gli.cas.cz/cej/www/
http://www.facebook.com/cejchan
work: +420-233 087 237
home/SMS: +420-720