O'Reilly logo

CoffeeScript Application Development Cookbook by Mike Hatfield

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Parsing fixed-width files

In this recipe, we will parse a fixed-width file by creating a simple streaming parser. Our sample file will contain fixed-width columns of strings, numbers, dates, and Boolean values of accounting data. Our goal is to count the records and get a total credit and debit amount for all records that have been posted.

Our sample file looks like the following:

Parsing fixed-width files

Getting ready

In this section, we will create our own parser for fixed-width files. When considering the features we would like for our basic parser, it should:

  • Work with a stream reader to allow parsing very large data files
  • Use a schema to define our column names, positions, ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required