--000e0cd2a17833987c0463bcbcdf
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit

2009/2/25 Bary Buz <sxetikos / hotmail.co.uk>

> Hello everyone,
>
> i am new to ruby and im having some problems trying to reformat a text
> file.
>
> Basically, i have a large log file which is around 200mb in the
> following format:
> ----------------------------------------------------------
> 1000000             name
> Status            :A
> Basetype          :2
> Version           :1.0
>   |
>   |
>  (more
>  fields)
>   |
> Name              :/file/name/etc
> 1000001             name
> Status            :B
> Basetype          :2
> Version           :a20
>   |
>   |
> Name              :/file/name/etc
> 1000002             name
> Status            :C
>   |
>
> ... and so on
>
>
> so for each 200mb file there are lot of entries.
>
> What i want to do is to open the file, read the data into an array,
> reformat the text and save it into another file with the following
> output:
>
> id, Status, Basetype, .... , Name
> 1000000, A, 2, ..... , /file/name/etc
> 1000001, B, 2, ..... , /file/name/etc



I would strongly recommend looking at Treetop (http://treetop.rubyforge.org/).
It's a parser generator that produces tree structures from text files using
a grammar that you specify. If you know regular expressions, it shouldn't be
too big a leap to use Treetop's grammar language.

For this particular task it may be overkill, but certainly worth looking at.

--000e0cd2a17833987c0463bcbcdf--