From: Junhui Liao Date: 2010-08-06T07:05:02+09:00 Subject: Re: my script just read one line? > This is how I'd do it (untested, just an idea): > > File.open("../data/test_2lines.tsv") do |file| > total_data = Array.new(4096) {[]} # Array containing an array for > each file we will generate > first_line = file.readline.chomp.split("\t") > first_line_times = first_line.each_slice(2).map{|time,signal| time} > file.each_line do |record| > record.chomp.split("\t").each_slice(2).with_index do |(time,signal), > index| > total_data[index] << "#{time.to_f - > first_line_times[index].to_f}\t#{signal}\n" > end > end > > total_data.each_with_index do |lines, index| > File.open("header_split_#{index}"+".tsv" , "w") do |f| > � f.puts total_data[index] > end > end > > Hope this helps, > > Jesus. Dear Jesus, I modified little, then the code worked. This new script just took 3 (THREE) minutes, it's incredible !!! Millions of thanks to you! My main reference book is <>, I don't know why in this book, I could not find these information, like each_with_index, and like the example of two items between two bars "||", map{|time,signal| time} ? Where I can find these information ? Thanks a lot in advance! Cheers, Junhui -- Posted via http://www.ruby-forum.com/.