Deleting the first two lines of a file using BASH or awk or sed or whatever

Amit picture Amit · Jan 13, 2012 · Viewed 71.3k times · Source

I'm trying to delete the first two lines of a file by just not printing it to another file. I'm not looking for something fancy. Here's my (failed) attempt at awk:

awk '{ (NR > 2) {print} }' myfile

That throws out the following error:

awk: { NR > 2 {print} }
awk:          ^ syntax error

Example:

contents of 'myfile':

blah
blahsdfsj
1 
2
3
4

What I want the result to be:

1
2
3
4

Answer

RobS picture RobS · Jan 13, 2012

Use tail:

tail -n+3 file

from the man page:

   -n, --lines=K
          output the last K lines, instead of the last 10; or use  -n  +K
          to output lines starting with the Kth