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
link|improve this question

feedback

1 Answer

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".

link|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. – ErikA 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!. – ErikA 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
show 3 more comments
feedback

Your Answer

 
or
required, but never shown

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