From element14 Community member, coder27, comes this handy option for "head":
https://www.element14.com/community/message/68833#68815
I just remembered that the head command allows a negative argument to mean
counting from the end. So you could say simply:
$ head --lines=-3 foo
to get all but the last 3 lines of file foo.
(note that there is a double dash in --lines.)
coder27, before remembering the negative argument, gave another interesting approach:
Here's another way, just for fun and educational value:
If you happen to know for sure that a file, call it foo, is 10 lines long,
you can get all but the last 3 lines by doing:
$ head -7 foo
It's usually dangerous to rely on your file always being a fixed length,
so you can find out how long foo is by doing:
$ cat foo | wc -l
You can combine these into a script that gets all but the last 3 lines
of an arbitrary sized file by doing:
$ z=`cat foo | wc -l`
$ z=`expr $z - 3`
$ head -$z foo
TGIF!
Drew