Raw Input Desired Output
Last 11 Line 
Last 10 Line 
Last  9 Line 
Last  8 Line 
Last  7 Line 
Last  6 Line 
Last  5 Line 
Last  4 Line 
Last  3 Line 
Last  2 Line 
Last  1 Line 
Last 11 Line 
Last 10 Line 
Last  9 Line 
Last  3 Line 
Last  2 Line 
Last  1 Line 
Script and Comments
Script1
[ 1] :loop
[ 2] $!{
[ 3] N
[ 4] 2,8b loop
[ 5] P;D
[ 6] }
[ 7] s/.*\n\(\([^\n]*\n\)\{2\}[^\n]*\)$/\1/
Comments
  1. 'Pattern space' is abbreviated to 'PS'.
  2. This script uses a 8-line 'sliding window' .
  3. To 'slide' the window, we use the N-P-D sequence. For example, if PS contains line 3 thru 10 of the datafile, the N-P-D sequence will
    • Append next line (line 11) by command 'N'.
    • Print the first line of PS (in this case, the 3rd line of data file) by command 'P'.
    • Then delete it by command 'D'.
      Note that command 'D' will make sed jump to the top of the script!
    The new contents of PS will be line 4 thru 11.
  4. For files containing more than 8 lines, Step [1] thru [4] constitute a loop. This loop will read in first 9 lines of the data file.
  5. When the end of file is reached, PS contains the last 8 lines of the data file. What we have to do is keeping last 3rd lines of PS and discard the others. This is done by Step [7].