From: Junhui Liao Date: 2010-08-05T06:22:04+09:00 Subject: Re: my script just read one line? Hi, Jesus, > You could read the lines one by one as you are doing now, but instead > of writing them to each file on each step, accumulate them in arrays. > For example you could have an array that contains and array of lines > for each file. Then when you've read the whole file, iterate through > the array writing each subarray to a file. > I tried to use the following code to make all of the line's data containing in an array. But my code just read the last line of file. Could you please tell my why? File.open("../data/test_2lines.tsv") do |file| total_data = []# Array containing all of the line_datas line_data = [] # Array just containing one line's data first_line = file.readline.chomp.split("\t") first_line_times = first_line.each_slice(2).map{|time,signal| time} file.each_line do |record| line_data = record.chomp.split("\t")# write all time and sginal into array line_data. end total_data = total_data + line_data# append line_data into total_data puts total_data.length File.open("total_data.txt","w") do |f| f << total_data end end However, under irb, irb(main):001:0> a = [1,2,3] => [1, 2, 3] irb(main):002:0> b = [4,5,6] => [4, 5, 6] irb(main):003:0> a + b => [1, 2, 3, 4, 5, 6] Thanks a lot in advance! Cheers, Junhui -- Posted via http://www.ruby-forum.com/.