title: How to use sed to remove the last n lines of a file
body: <p>I want to remove some <em>n</em> lines from the end of a file. Can this be done using sed?</p>
  
  <p>For example, to remove lines from 2 to 4, I can use</p>
  
  <pre><code>$ sed '2,4d' file
  </code></pre>
  
  <p>But I don't know the line numbers.  I can delete the last line using </p>
  
  <pre><code>$sed $d file
  </code></pre>
  
  <p>but I want to know the way to remove <em>n</em> lines from the end. Please let me know how to do that using sed or some other method.</p>