By definition a line must end with newline character (\n
) (ref.). But for the purpose of this post, I will consider any series of characters as a line whether or not it finishes with \n
.
The command tail -n 1
returns the last line whether or not it ends with \n
. How can one get from a file the last line that ends with \n
whether or not this line is the last line or the second-to-last line of the file?