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

Re: rs in debian

On Wed, May 10, 2006 at 11:02:06AM +0200, Lubos Vrbka wrote:
} > is there any alternative to (bsd-based, imho) utility rs in debian? i
} > tried to find it, but to no avail... or maybe i just missed some
} > essential package?
} maybe i should add what i need it to do -
} i have a text file. datasets are formed by lines, values are
} white-character separated. now i need to create a transpose of this
} file, i.e. convert rows to columns.

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.)

#!/usr/bin/env ruby

dataset = ARGF.inject([]) do |arr,line|
  arr << line.scan(/\w/).inject([]) do |row,word|
    row << word
print dataset.transpose.map! { |row| row.join("\t") }.join("\n")
puts ""

} thanks,
} Lubos

Reply to: