Tail/head all line except X last/first Lines

bashcentosheadsshtail

for example i have this file :

cat myfile
1
2
3
4
5

i want to print all lines except first 2 line . output should be like this :

tail -n $(( $(wc -l myfile | awk '{print $1}') - 2 )) myfile
3
4
5

Yes , out put is correct. but there is a problem , we have 5 line in this sample file right ? if i use more that 5 in this command output should be empty but it is not !!!

tail -n $(( $(wc -l myfile | awk '{print $1}') – NUMBER ))
myfile

this outout should be empty but it is not

tail -n $(( $(wc -l myfile | awk '{print $1}') - 8 )) myfile

1
2
3
4
5

myfile can contain X lines…
Thanks for help

Best Answer

tail -n+3 outputs the last lines starting from the third one.

Related Question