in reply to loop by line on a file

What do you mean "it only loops once"? The code does loop through the entire input file, line by line.