Parsing Fixed Width File

N

Nick da G

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?
 
A

Anthony Eden

Did you look at the ActiveWarehouse ETL docs:
http://activewarehouse.rubyforge.org/docs/activewarehouse-etl.html ?
If nothing else you might be able to look at the existing fixed width
file parser and use that as a starting point.

Sincerely,
Anthony Eden

Hello, all.
Does anyone know of a good =A0or 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?



--=20
GMU/IT d- s: a32 C++(++++)$ UL@ P--- L+(++) !E W+++$ !N o? K? w--- !O
M++ V PS+ PE Y PGP t+ !5 X- R tv b++ DI+ D++ G- e++ h---- r+++ y++++**

http://anthony.mp
 
A

Andrew Timberlake

Hello, all.
Does anyone know of a good =A0or 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 =3D [5,12,5,2,20] #<- the size of each field
field_pattern =3D "A#{fields.join('A')}"
File.foreach(filename) do |line|
row =3D 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
 
N

Nick da G

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


Yeah that's pretty much what I ended up doing.
Created an object that defines each record (line)

then pass it at a line from file, and get an object back that I can do
what I want with - like outputing to csv .

I was jsut wondering if there was a more simple and elegant solution.
But I guess you can't go simpler than that. :) Thanks for a response!
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top