[Radiance-general] Research tools: who what which how?

Christopher Rush Christopher.Rush at arup.com
Wed Apr 13 10:01:52 PDT 2016


For a trivial example of transposing a matrix tab delimited data file... which of these is most easily understood, reproducible, and fastest. Also note, I couldn't find a working Ruby example...


perl -anF'\t|\n' -e'$n=@F-1if!$n;for(0..$n){push@{$$m[$_]},$F[$_]} END{print map{join"\t",@$_,"\n"}@$m}'
^^ this takes a quarter of a second on 148K file, and doesn't look particularly clean but I could probably figure it out by researching the documentation

python -c "import sys; print('\n'.join(' '.join(c) for c in zip(*(l.split() for l in sys.stdin.readlines() if l.strip()))))"
^^ this takes half a second on 148K file but looks a bit baffling to me

awk '{for (f=1;f<=NF;f++) col[f] = col[f]":"$f} END {for (f=1;f<=NF;f++) print col[f]}' | tr ':' ' '
^^ this takes 2 seconds on 148K file which isn't very good, but probably the easiest to interpret by eye, in my opinion

ruby -e 'puts readlines.map(&:split).transpose.map{|x|x*" "}'
^^ I couldn't make this or any other Ruby examples I found online work, which might mean I have a basic misunderstand of how to type this in a single line workflow on the terminal. And all the examples I could find look like a black box to me because apparently there are functions built in to do this task.

echo '' >tmp1;  cat m.txt |while read l ; do paste tmp1 <(echo $l | tr -s ' ' \\n)>tmp2; cp tmp2 tmp1; done
^^ this series of commands is basically disqualified because it takes far too long


Taken from these threads:
http://stackoverflow.com/questions/1729824/transpose-a-file-in-bash
http://stackoverflow.com/questions/3249508/transpose-in-perl

____________________________________________________________
Electronic mail messages entering and leaving Arup  business
systems are scanned for acceptability of content and viruses




More information about the Radiance-general mailing list