Hi,

I have stumbled on an interesting problem. I have thought 'n' thought, but haven't come up with any good ideas of how to handle this.

I have a text file that contains many records, but without the records being seperated. I need to figure out how to seperate these files, or at least how to write a program that recognizes different records and can then seperate them.

I don't expect anyone to write my program for me, but I need help seperating the records.

The beginning of every record looks like this: MSUBUGA JIMSON
P O BOX 21273
GABORONE
(Obviously they are all different, but always have 3 values on 3 lines.)
The end looks like this:
P107.17 P0.00 P225.08 P0.00 P332.25
(The numbers always vary, but there are always 5)

Any help will be greatly appreciated, Thank you.

The beginning of every record looks like this: MSUBUGA JIMSON
P O BOX 21273
GABORONE
(Obviously they are all different, but always have 3 values on 3 lines.)
The end looks like this:
P107.17 P0.00 P225.08 P0.00 P332.25
(The numbers always vary, but there are always 5)

So each record is 4 lines total (with only 3 lines we care about).

Can you give an small snippet of a file with at least two records for example? I envision either simply taking every 4 lines and parsing out the relevant info, or if there is a blank line between each record, just split at the blank lines.

If you read the file in with readlines() , using index slicing you can easily grab groups of lines.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.