I would like to simulate GNU\'s head -n -3, which prints all lines except the last 3, because head on FreeBSD doesn\'t have this feature. So I am t
head -n -3
head
Another Awk solution that only uses minimal amount of buffers and prints lines quickly without needing to read all the lines first. It can also be used with pipes and large files.
awk 'BEGIN{X = 3; for(i = 0; i < X; ++i)getline a[i]}{i %= X; print a[i]; a[i++] = $0}'