I want to add a newline at the end of a file only if it doesn\'t exists, this is to prevent multiple newlines at the end of the file.
I\'m hoping to use sed. Here\'s the
Try using vi or ex:
vi
ex
ex -scwq foo.txt
or for multiple files:
vi -es +"bufdo wq" *.txt ex -s +"bufdo wq" *.txt
which automatically adds EOL at EOF on file save if it's missing.
To apply for certain files recursively, use a new globbing option (**) such as **/*.txt (enable by shopt -s globstar).
**
**/*.txt
shopt -s globstar