From: Andrew Timberlake Date: 2009-04-15T12:08:18+09:00 Subject: Re: Parsing Fixed Width File On Wed, Apr 15, 2009 at 12:13 AM, Nick da G wrote: > Hello, all. > Does anyone know of a good  or any for that matter library (gem) to > parse fixed width files? > > I've looked into active-warehouse - but it looks like it's for rails > only and docs are a bit underdeveloped for it. > > Any ideas anyone? > -- It's pretty simple so I'm not sure that a library is needed fields = [5,12,5,2,20] #<- the size of each field field_pattern = "A#{fields.join('A')}" File.foreach(filename) do |line| row = line.unpack(field_pattern) ... #use row[0] etc for each field end Andrew Timberlake http://ramblingsonrails.com http://www.linkedin.com/in/andrewtimberlake "I have never let my schooling interfere with my education" - Mark Twain