why don't you fix it at the right place where newlines are appended ?