Missing The Last Line in a File
suggest changeThe C standard says that files should end with a new line, so if EOF comes at the end of a line, that line may not be missed by some commands. As an example:
$ echo 'one\ntwo\nthree\c' > file.txt$ cat file.txtonetwothree$ while read line ; do echo "line $line" ; done < file.txtonetwo
To make sure this works correctly for in the above example, add a test so that it will continue the loop if the last line is not empty.
$ while read line || [ -n "$line" ] ; do echo "line $line" ; done < file.txt
one
two
three
Found a mistake? Have a question or improvement idea?
Let me know.
Table Of Contents