Add new line character at the end of file in bash Add new line character at the end of file in bash bash bash

Add new line character at the end of file in bash


echo "" >> file.txt

Adds a newline character at the end


With sed:

sed -i '' -e '$a\' file.txt

with echo:

echo  >> file.txt


Use Vi which automatically creates EOL at EOF on file save.

For example:

vi -escwq foo.txt

or:

ex -scwq foo.txt

To correct multiple files, check: How to fix 'No newline at end of file' for lots of files? at SO