Take the 2-minute tour ×
Server Fault is a question and answer site for professional system and network administrators. It's 100% free, no registration required.

When I run some bash command it returns 2 .. n lines of text (n is different each time, may contain blank lines).

How to filter the output to display the result skipping lines 1 and 2?

e.g.

$ my_command

file1
file2
file3
file3

$ my_command | some_filter

file3
file4
share|improve this question

1 Answer 1

up vote 8 down vote accepted
$ my_command | tail -n +3

In this case, the +3 means "start output at the third line of the file".

share|improve this answer
2  
my_command | tail -n +3 –  Iain Sep 28 '10 at 21:08
    
@Iain, The -n without a number following it doesn't do anything. The -n flag only matters when you want the last X lines of a file. –  EEAA Sep 28 '10 at 21:14
2  
@ErikA: seems to matter on the centos and ubuntu systems I have to hand. ls | tail +3 tail: cannot open +3 for reading: No such file or directory –  Iain Sep 28 '10 at 21:20
1  
Huh, interesting. It works fine on a RHEL4 server without the -n, but not RHEL5 or Debian. Must have been a fluke in an old version of tail. I've edited my answer accordingly, thanks!. –  EEAA Sep 28 '10 at 21:22
1  
If your particular 'tail' command isn't playing ball, use: awk 'NR>2 {print}' –  MikeyB Sep 28 '10 at 22:58

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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