[Tutor] Scanning a file for specific text and copying it to a new file

Ben Ganzfried ben.ganzfried at gmail.com
Thu Dec 2 19:27:44 CET 2010


I'm trying to build a program that reads in a file and copies specific
sections to a new file.  More specifically, every time the words
"summary on" are in the original file, I want to copy the following
text to the new file until I get to the words "summary off".

My questions are the following:
1) Once I have read in the old file, how do I copy just the parts that
I want to the new file?  What command do I give the computer to know
that "summary on" (whether capitalized or not) means start writing to
the new file-- and "summary off" means stop?  Also, I assume I'll put
all of this in a while loop based on the condition that we should read
until we are done reading the whole document?  (although, this is
somewhat inefficient because the last "summary on/off" could be way
before the end, but this is preferable to missing one that is at the
end...)

Thank you very much for any help you can provide.  Much appreciated!

Ben


More information about the Tutor mailing list