Forum Moderators: coopster

Message Too Old, No Replies

Want to Parse a Text File

         

moonsurfer

4:29 pm on May 5, 2011 (gmt 0)

10+ Year Member



This text file is a batch full of invoices. What I want to do is parse the info so I can import it into a database.

The file doesn't seem to have delimiters, however, in between each invoice is a page break marked by "$END".

Can someone give me a hint on where to get started so I can extract and organize the data I need?

Thanks for the help!

Here's a link to the text file: [tiny.cc ]

eelixduppy

8:08 pm on May 5, 2011 (gmt 0)



A text file like this is going to be very difficult to parse the way you want. Is there any other way you can get this information?

Welcome to WebmasterWorld, btw! :)

moonsurfer

1:24 am on May 6, 2011 (gmt 0)

10+ Year Member



Thx for the welcome! :) I look forward to contributing on this forum where I can. :)

On the text file... I was afraid of that. This invoice batch file is generated through a function in the program that a client uses.

I guess I'll just have to get in touch with the company that developed the software to make headway. Thanks a lot for your help and I look forward to returning the favor someday.

caribguy

1:59 am on May 6, 2011 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Line 1-4 (always the same sender?)
Sender's Name, Address, City + Zip, Phone

(for bonus points split first line on more than n spaces or tab stops or whatnot and grab the print date)?

(if address line can be multiple, you start at 2 and find a line with the zipcode, anything in between is address)

Line 5-7
Recipient's Name, Address, City + Zip

Line 8
Account ID

Line 9-11 Heading, skip

Line 12-14 (and repeat every three lines)
- 12 split on n spaces/tabs
8 character date, item description, their charge, ins pending, owed amount
-13 date, description, insurance paid
-14 date, description, insurance paid

repeat until you hit the footer (starts with a bunch of spaces)
Account balance, amount
Please pay, amount

(bonus points if these amounts don't match the total something's wrong)
$END$

Hint, do a first pass to collect all the items and descriptions so that you can build a normalized db from the get go...