[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: rs in debian



On Wed, May 10, 2006 at 02:27:26PM +0200, Lubos Vrbka wrote:
} > Here's a Ruby script. You will need to apt-get install ruby to use it if
} > Ruby is not already installed. (I did it in awk as well, but the Ruby
} > solution is much easier to read.)
} thanks a lot. however, i'd be interested to see your solution in awk as well

#!/usr/bin/awk -f

BEGIN { maxcols = 0; }

{
	for (i=1;i<=NF;++i)
		dataset[NR,i] = $i;
	if (maxcols<NF)
		maxcols = NF;
}

END {
	for (i=1;i<=maxcols;++i) {
		for (j=1;j<NR;++j)
			printf("%s\t", dataset[j,i]);
		printf("%s\n", dataset[NR,i]);
	}
}


} > #!/usr/bin/env ruby
} > 
} > dataset = ARGF.inject([]) do |arr,line|
} >   arr << line.scan(/\w/).inject([]) do |row,word|
} >     row << word
} >   end
} > end
} > print dataset.transpose.map! { |row| row.join("\t") }.join("\n")
} > puts ""
} > 
} > } thanks,
} > } Lubos
} > --Greg
} Lubos
--Greg



Reply to: