I can't test it cause I am not at home and can't install Python here.
And I should not write a full working code but... I can't explain what is in my head very well. My English is not so good as I need for this.
with open(file_name, 'r') as f: book = f.readlines() while book: line = book.pop(0) if "CHAPTER" in line and book.pop(0) == '\n': for title in chapters_names_list: # your lies of chapter names here with open("{}.txt".format(chapters_names_list), 'w') as f: try: while True: line = pop(0) if 'CHAPTER' in line: break else: f.write(line) except IndexError: passWhile this might work but you should look at @snipsat code snipped. It seems to be more clear than this. If you decide to use the code above it will be empty lines in the text. One above the title and at the end of the chapter a few more.
And I should not write a full working code but... I can't explain what is in my head very well. My English is not so good as I need for this.