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
takeshin
  • 1,471
  • 3
  • 21
  • 28

1 Answers1

8
$ my_command | tail -n +3

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

EEAA
  • 109,363
  • 18
  • 175
  • 245
  • 2
    `my_command | tail -n +3` – user9517 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 – user9517 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
  • I am curious now - does it work with -n +3 on the old server ? – user9517 Sep 28 '10 at 21:34
  • Yep, works fine. Functionality is identical either with or without the `-n`. – EEAA Sep 28 '10 at 21:36
  • The form without the `-n` is obsolete in GNU `tail` and `head` according to `info coreutils 'tail invocation'` (also documented in [POSIX](http://www.opengroup.org/onlinepubs/9699919799/utilities/tail.html) ). – Dennis Williamson Sep 28 '10 at 21:49
  • 1
    If your particular 'tail' command isn't playing ball, use: `awk 'NR>2 {print}'` – MikeyB Sep 28 '10 at 22:58