title: How can I read first n and last n lines from a file?
body: <p>How can I read the first n lines and the last n lines of a file?</p>
  <p>For <code>n=2</code>, I read <a href="https://unix.stackexchange.com/questions/139089/how-to-read-first-and-last-line-from-cat-output">online</a> that <code>(head -n2 &amp;&amp; tail -n2)</code> would work, but it doesn't.</p>
  <pre><code>$ cat x
  1
  2
  3
  4
  5
  $ cat x | (head -n2 &amp;&amp; tail -n2)
  1
  2
  </code></pre>
  <p>The expected output for <code>n=2</code> would be:</p>
  <pre><code>1
  2
  4
  5
  </code></pre>