AWK (stolen from Ed (not the editor!))
NR < 11 {
buf[NR] = $0; next
}
NR >=11 {
print
if (NR == 11) {
for (i=1; i<11; i++) { print buf[i] }
}
}
I used NR instead of incrementing n, and made the flow more explicit. Same "trick": the next simplifies downstream.
With perl -n
$n++ ;
$tmp = $tmp . $_ if $n < 11 ;
print $_ . $tmp if $n == 11 ;
print if $n > 11 ;
This is the best format. Symmetrical.