title: Reverse lines in a file two by two
body: <p>I'm trying to reverse the lines in a file, but I want to do it two lines by two lines.</p>
  
  <p>For the following input:</p>
  
  <pre><code>1
  2
  3
  4
  …
  97
  98
  </code></pre>
  
  <p>I would like the following output:</p>
  
  <pre><code>97
  98
  …
  3
  4
  1
  2
  </code></pre>
  
  <p>I found lots of ways to reverse a file line by line (especially on this topic: <a href="https://stackoverflow.com/questions/742466/how-can-i-reverse-the-order-of-lines-in-a-file">How can I reverse the order of lines in a file?</a>).</p>
  
  <ul>
  <li><code>tac</code>. The simplest. Doesn't seem to have an option for what I want, even if I tried to play around with options <code>-r</code> and <code>-s</code>.</li>
  <li><code>tail -r</code> (not POSIX compliant). Not POSIX compliant, my version doesn't seem to have anything to do that.</li>
  </ul>
  
  <p>Remains three sed formula, and I think a little modification would do the trick. But I'm not even understanding what they're doing, and thus I'm stuck here.</p>
  
  <pre><code>sed '1!G;h;$!d'
  sed -n '1!G;h;$p'
  sed 'x;1!H;$!d;x'
  </code></pre>
  
  <p>Any help would be appreciated. I'll try to understand these formula and to give answer to this question by myself.</p>