Why do some text editors offer to end your file with a line break? Why is that important?

2

Why do some text editors such as BBEdit and Textmate offer to end your file with a newline (line break)? Why is that important?

Are there any caveats to not ending a file with a line break?

racl101

Posted 2011-07-27T01:17:01.000

Reputation: 206

Answers

4

Some Unix-style text processing commands may produce unexpected behavior if the last line does not end with a newline. For example, wc -l counts the number of lines in a file, but it does so essentially by counting the newline characters, so the last "line" isn't counted. Some other programs also miss the last line if it's not terminated by a newline.

juggler

Posted 2011-07-27T01:17:01.000

Reputation: 1 530

1As another example, if you used cat to combine two files and the last line of the first file did not end with a newline, then the last line of the first file and the first line of the second file would be joined as one line. The Unix convention is that a newline is a line terminator, not a line separator. – garyjohn – 2011-07-27T05:10:05.063