14

Say I have a file with any number of lines, say, 125. I want to get all the lines except the first n, say, 20. So, I want lines 21–125.

Is there a way to do this with with tail/head, or some other tool?

codeforester
  • 39,467
  • 16
  • 112
  • 140
kch
  • 77,385
  • 46
  • 136
  • 148
  • 4
    If you want to know what head/tail can do, read the man pages for them. If you did not know that head/tail existed, I could understand why you'd ask the question, but explicitly asking about head/tail deserves a RTFM response. – camh Nov 29 '08 at 01:39
  • Linked: http://stackoverflow.com/questions/604864/print-a-file-skipping-x-lines-in-bash – Prof. Falken Jan 16 '13 at 09:09

4 Answers4

34

Try

tail -n +21 myfile.txt
unwind
  • 391,730
  • 64
  • 469
  • 606
5

Try

sed -i 1,20d filename

if you want to delete the first 20 lines !

Vijay Dev
  • 26,966
  • 21
  • 76
  • 96
3

Awk power can be used too:

awk -- 'NR > 20' /etc/passwd
Johannes Schaub - litb
  • 496,577
  • 130
  • 894
  • 1,212
3

I'm rusty with this but something like: tail -n +20 filename

Rotem
  • 442
  • 2
  • 8