title: Add a newline only if it doesn't exist
body: <p>I want to add a newline at the end of a file only if it doesn't exist. This is to prevent multiple newlines at the end of the file.</p>
  <p>I'm hoping to use <code>sed</code>.
  Here are the issues I'm having with my current code:</p>
  <pre><code>sed -i -e '/^$/d;$G' /inputfile
  
  echo file1
  name1
  name2
  
  echo file2
  name3
  name4
  (newline)
  </code></pre>
  <p>when I run my code on to the files;</p>
  <pre><code>echo file1
  name1
  name2
  (newline)
  
  echo file2
  name3
  name4
  </code></pre>
  <p>it adds a newline if it doesn't have one but removes it if it exists... this puzzles me.</p>