From: "Jesús Gabriel y Galán" Date: 2010-08-03T15:17:24+09:00 Subject: Re: my script just read one line? On Tue, Aug 3, 2010 at 12:15 AM, Junhui Liao wrote: > Hi, Jesus, > > >> Maybe you can read it completely in memory, reorganize the contents >> per file, and then write each file at once. >> I think that should speed it up, although it implies a complete >> refactor of the code. > > > Could you please give me some tips on how to organize this new script ? > I have no idea to do this at all. 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. > >> Item 2, the original data has 21 lines header. Although it could be >>> deleted then read by the script. But I do want to update the script >>> to make it exclude the fist 21 lines header. >> >> If you do a first file.readline after opening the file, you will read >> the first line. >> Then continue with what you already had. > > > As to this problem, I solved by insert this code. > >  until file.readline =~ /Data:/ >  file.readline >  end Be careful, you are doing two readlines per iteration, so you might skip the important line. If you know you have only one line before the important data you can just do file.readline and continue. Jesus.