I realize that your question is about how to solve collecting multiple lines but since I notice that you're trying to read PDB files then you might find this program useful. Of course, if you just posted this as an exercise in theory and have no interest in the file you're using as an example then ignore this post.
Moleman2
metadoktor
"The doktor is in."