------ art_69826_29996330.1176824995656 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit Content-Disposition: inline Thanks for asking for clarification. I frequently have to turn CSV files into files that follow different fixed-width formats. So it's not that I need to unpack my data. Rather, I need a way to take csv'd data, and a separate file format or even specification, and "pack" the CSV data into the format. For example, right now I need to generate a nightly batch file with headers and footers and arbitrarily complicated field specifications from a largish csv file. And the formats that I have to satisfy are often complex, so doing one-off conversion scripts can get to be a pain to maintain very quickly. Your FasterCSV and String#unpack seem like a great place to start. At a minimum, I need to be able to attach rules to each field like the number of positions (as well as packing character, eg, whitespace or zeroes, and maybe formulas based on other field values) in my format string. Is there an equivalent of String#pack out there? Steve On 4/17/07, James Edward Gray II <james / grayproductions.net> wrote: > > On Apr 17, 2007, at 1:40 AM, Stephen Smith wrote: > > > So here's the problem: I have a CSV file that I need to munge into > > a batch > > file for a mainframe to process. This file has many (say, 30 or > > more) fixed > > width fields per record with distinct rules attached to each field > > (e.g., > > field1 is an eight-position date following the pattern YYYYMMDD, > > field2 is a > > five-position enumerated customer type, field3 may contain either a > > 70 or a > > 71 depending on the customer type, etc). > > I'm a little confused by your description of the file. You call it a > CSV file and say it has fixed-width fields, but those are two > different things. > > Either way though, Ruby has the tools you need. > > For CSV data, see the standard "csv" library. For splitting up fixed > width fields, a call to String#unpack will do. > > Hope that helps. > > James Edward Gray II > > > ------ art_69826_29996330.1176824995656--