Fix read last line to use tail

Had a problem with an infinite loop in the last version of the code.