Heads or Tails?
There is a command, head, to take the first piece of a file.
There is a command, tail, to take the last piece of a file.
Tail does a few extra things, because it's useful to watch the end of a file that is being updated and similar things, but they should be pretty similar pieces of code, supporting similar options, right?
head supports a negative number of lines as argument, meaning "all but the last N lines", and tail doesn't.
Same about bytes instead of lines
That means that you can't quite simply get "all but the first two lines of this file".
But don't worry, this is how you do it:
tac file |head --lines=-2 | tac
Correction: tail has what I wanted. I am just a silly guy that doesn't read the man pages completely, you can do tail
-n +2 to do it.
On the other hand, it's not explained in the option, and the syntax is different from head's, so it's still slightly rant-worthy ;-)
(read l; read l;while read l;do echo $l;done) < file
works too... :-)
tail -n +3
starts with the third line
And it works for -c too :
tail -c +20 to start at the 20th character.
The most awfull is, it's even stated in the manpage :)
"If the first character of N (the number of bytes or lines) is a `+', print beginning with the Nth item from the start (...)"
Not on the linux manpage!
output the last N lines, instead of the last 10
And anyway, it's completely different from head's
print the first N lines instead of the first 10; with the leading ‘-’, print all but the last N lines of each file
This one I got in the mail from Dirk Eddelbuettel:
sed '1,10d' filename
Works, and is simplest yet.
Oops, sorry, it **is** in the linux manpage... it's just not in the place where the option is described.