On Fri, Aug 6, 2010 at 12:05 AM, Junhui Liao <junhui.liao / uclouvain.be> wrote:
>
>> 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 <<Programing ruby_the progmatic programmers>>,

Are you referring to this one: http://www.ruby-doc.org/docs/ProgrammingRuby/

> I don't know why in this book, I could not find these information, like
> each_with_index,

Well, I don't know if it's mentioned in the text, but there's a reference:

http://www.ruby-doc.org/docs/ProgrammingRuby/html/ref_m_enumerable.html#Enumerable.each_with_index

> and like the example of two items between two bars "||",
> map{|time,signal| time} ?
> Where I can find these information ?

... but I recommend you take a look at the API reference here:

http://ruby-doc.org/core/

and study the classes: Array, Hash and Enumerable, which are pretty
important to master (of course there are others like String and so
on...)

Jesus.