Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is it recommended to have empty line in the end of a source file?

Some code style tools recommend this and I remember seeing some unix command line tools warning about missing empty line.

What is the reasoning for having an extra empty line?

like image 656
Petteri H Avatar asked Feb 18 '10 10:02

Petteri H


People also ask

Should you have new line at end of file?

So, it turns out that, according to POSIX, every text file (including Ruby and JavaScript source files) should end with a \n , or “newline” (not “a new line”) character. This acts as the eol , or the “end of line” character. It is a line “terminator”.

How the blank lines are deleted from the file?

Delete blank lines using the grep command When used with the -v option, the grep command helps to remove blank lines. Below is a sample text file, sample. txt, with alternative non-empty and empty lines. To remove or delete all the empty lines in the sample text file, use the grep command as shown.

How do I add a line to the end of a file in Linux?

Append Text Using >> Operator Alternatively, you can use the printf command (do not forget to use \n character to add the next line). You can also use the cat command to concatenate text from one or more files and append it to another file.


1 Answers

Many older tools misbehave if the last line of data in a text file is not terminated with a newline or carriage return / new line combination. They ignore that line as it is terminated with ^Z (eof) instead.

like image 185
Ralph M. Rickenbach Avatar answered Jan 04 '23 09:01

Ralph M. Rickenbach