hey guys!
i need to read data from a file that are comma separated then reorder them in another file to be generated
for example:
x,y,z
a,b,c
l,m,n
o,p,q
and transform this into:
x,a,l,o
y,b,m,p
z,c,n,q
Will appreciate your fast reply
Regards!
panyam
2
awk -F"," 'NR==1{for(i=1;i<=NF;i++)a=$i;next} {for(i=1;i<=NF;i++) a=aOFS$i} END{for(i=1;i in a;i++) print a}' OFS="," input_file
check it out on how to get the output in the same order you read it.
Try:
perl -F, -alne 'for ($i=0;$i<=$#F;$i++){push @{$h{$i}},$F[$i]}END{for ($i=0;$i<=$#F;$i++){$,=",";print @{$h{$i}}}}' file
kurumi
4
Ruby(1.9.1+)
$ ruby -ne 'BEGIN{a=[]};a<<$_.chomp.split(",");END{a.transpose.each{|x| puts x.join(",") }}' file
x,a,l,o
y,b,m,p
z,c,n,q
is this a language other that shell scripting? am sorry am a beginner
mirni
6
i=1; while true ; do a=`cut -d, -f$i file` ; ((i++)); [ "$a" ] || break ; echo $a | tr ' ' ',' ; done