4

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

11

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

  • line number are variable and i dont know how many line there are . want to keep all except last 3 lines – network Apr 29 '16 at 23:51
  • That's not what you described in the question, but head -n-3 should give you what you need. – choroba Apr 29 '16 at 23:53
  • i have edit question. but this file is output of a script and we dont know how many line have ... – network Apr 29 '16 at 23:58
  • You don't need to know the number of lines. – choroba Apr 29 '16 at 23:59
  • 1
    tried is it not what i need for example if i want have all line except 8 lines but i have 5 line only .so output should be empty :tail -n-8 myfile 1 2 3 4 5 – network Apr 30 '16 at 0:07

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.