0

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

1 Answer 1

8
$ my_command | tail -n +3

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

8
  • 2
    my_command | tail -n +3
    – user9517
    Sep 28, 2010 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, 2010 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
    – user9517
    Sep 28, 2010 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, 2010 at 21:22
  • 1
    If your particular 'tail' command isn't playing ball, use: awk 'NR>2 {print}'
    – MikeyB
    Sep 28, 2010 at 22:58

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .