[snip] now ponder this: f=file("prueba.txt.log") for startline in f: if startline.find("2") != -1: for endline in f: print endline # etc.