The number of lines options with
head and
tail do not have to be negative...
After 15 years of using head and tail (and wondering why they encourage the use of the "extra" '-n' option now!) a question just occurred to me...
"What if I don't know how many lines I want to see with tail, I just know I want to skip the first X lines...?"
The logical opposite of:
tail -X FILENAMEwould of course be:
tail +Y FILENAMEWhich (thanks to Unix being so logical) naturally works!
You wouldn't really want to use it without a -n in front because +NUM would more likely be a valid file name than a switch, so you do get a warning:
$ tail +20 FILENAME
tail: Warning: "+number" syntax is deprecated, please use "-n +number"
and head just barfs:
$ head +20 FILENAME
head: cannot open `+20' for reading: No such file or directory
So use:
$ tail -n +$SKIP FILENAME
Given the file:
$ seq 1 5 > FILENAME
$ cat FILENAME
1
2
3
4
5
Let's unit test...
$ head +2 FILENAME
head: cannot open `+2' for reading: No such file or directory
==> FILENAME <==
1
2
3
4
5
means: "head the files '+2' and 'FILENAME'"
$ head -2 FILENAME
1
2
$ head -n 2 FILENAME
1
2
$ head -n +2 FILENAME
1
2
all mean: "show the first 2 lines of FILENAME"
$ head -n -2 FILENAME
1
2
3
means "show all BUT the last 2 lines of FILENAME"
$ tail +2 FILENAME
tail: Warning: "+number" syntax is deprecated, please use "-n +number"
2
3
4
5
means "I'm being too lazy to use -n, but show me FILENAME from line 2 down"
$ tail -2 FILENAME
4
5
$ tail -n 2 FILENAME
4
5
$ tail -n -2 FILENAME
4
5
mean "Show me the last 2 lines of FILENAME"
$ tail -n +2 FILENAME
2
3
4
5
means "Show me FILENAME from line 2 down"