title: bash sed to remove all whitespace and blank lines from end of file
body: <p>I found this to remove whitespace from the end of a script <a href="https://stackoverflow.com/questions/4438306/how-to-remove-trailing-whitespaces-with-sed">How to remove trailing whitespaces with sed?</a> but it doesn't quite do what I was hoping. What I would like to do when I think of remove all white space is to remove also any empty lines - I think that this <code>sed</code> just removes spaces and tabs, but can it be expanded to also trim out any empty lines from the end of the file? Maybe it's not possible to do this with one line, and maybe there are better ways to achieve this, any options are great.</p>
  <p>Also, am I right in thinking that this should replace the file in place with the changes? I'm just not sure that's happening in my testing.</p>
  <pre><code>sed -i 's/[ \t]*$//' ~/.bashrc
  # -i is in place, [ \t] applies to any number of spaces and tabs before the end of the file &quot;*$&quot;
  </code></pre>