title: awk to copy and move of file last line to previous line above
body: <p>In the <code>awk</code> below I am trying to move the last line only, to the one above it. The problem with the below is that since my input file varies (not always 4 lines like in the below), I can not use <code>i=3</code> everytime and can not seem to fix it.  Thank you :). </p>
  
  <p><strong>file</strong></p>
  
  <pre><code>this is line 1
  this is line 2
  this is line 3
  this is line 4
  </code></pre>
  
  <p><strong>desired output</strong></p>
  
  <pre><code>this is line 1
  this is line 2
  this is line 4
  this is line 3
  </code></pre>
  
  <p><strong>awk</strong> (seems like the last line is being moved, but to i=2)</p>
  
  <pre><code>awk '
      {lines[NR]=$0}
      END{
          print lines[1], lines[NR];
          for (i=3; i&lt;NR; i++) {print lines[i]}
      }
  ' OFS=$'\n' file
  
  this is line 1
  this is line 2
  this is line 4
  this is line 3
  </code></pre>