fix an edge case where last line does not end with '\n'