Splitting Text files
Brandon Beck
bbeck at REMOVE-THIS-TO-EMAIL-ME.austin.rr.com
Wed Jul 3 02:49:46 EDT 2002
Ken Seergobin wrote:
> X-No-Archive:Yes
>
>
> I've looked around, but have been unable to locate a
> good example of how to split a text file. Specifically,
> I have datafiles with an identification line marked
> with the name of a BMP file followed by many lines of
> data. This repeats a number of times for each datafile.
> Within the data lines I'm only interested in extracting the
> those with a specific keyword. Ultimately, I'd like to have
> a datafile for each BMP listed in the original file.
>
> Suggestions would be appreciated. I really couldn't make
> sense of the regular expression notes I found.
>
> Thanks,
> Ken
>
>
I've written something to do exactly this, with the data all on one
line, not spanning multiple lines. It obviously not exactly what you
want but it should give you a good base to work off of if you're
interested in extending it.
Main directory:
http://isomorphism.org/~bbeck/splitter/
Splitting algorithm:
http://isomorphism.org/~bbeck/splitter/splitter.py
Sample splitter:
http://isomorphism.org/~bbeck/splitter/FirstNameSplitter.py
Sample data (for FirstNameSplitter.py):
http://isomorphism.org/~bbeck/splitter/input.txt
Hope this helps,
Brandon
More information about the Python-list
mailing list