If you need assistance in parsing text files, you can use commercial applications designed to handle the job like Monarch. There's also many tools and utilities designed to view and parse text files. Both Scott Hanselman and Buck Woody have detailed lists that you should peruse and explore.
But let's our skills and tackle the problem programatically.
The nice thing about many of the fixed-width text reports is they are very consistent in layout and organization, making them easy to parse. If they are generated from an accounting system that includes the GL, (General Ledger), account number on each row, then you probably have the key to pulling out the information needed on a periodical basis. Let's see an small example.
Federal Borrowings Program |
Sometimes you don't need every row since you don't want to load the data back into a database, you want to pull out specific totals and sub totals. It's easy enough to feed a list of account numbers or GL items to a routine, along with a list of position and widths of the account/items and the position and widths of the balances. You then end up with a dictionary, (Python, C#), a data structure that you can reference for calcutions or export/return to be handled by another process. The process is something like this:
- Pass file name and list of items to a routine
- Create a dictionary structure with the list of items as the key values
- Read in each line of the file, looking for matching keys, (using position and width)
- If match found, populate the value for the matching key, (using position and width)
- Continue till done with file.
- Export dictionary to files, do calulations, or whatever.
Then use the following method:
No comments:
Post a Comment