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
Using awk :
awk '/^$/{f=1}END{ if (!f) {print "\r"}}1' inputfile
Match blank line ^$(just like you did) and set up a flag. If flag is not set at the end, place newline character.
^$
Note: that \r is in OS X. Use \n for other.
\r
\n