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
  • 34,080
  • 14
  • 96
  • 122
kch
  • 74,261
  • 45
  • 130
  • 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
  • 378,987
  • 63
  • 458
  • 590
5

Try

sed -i 1,20d filename

if you want to delete the first 20 lines !

Vijay Dev
  • 25,766
  • 20
  • 75
  • 96
3

Awk power can be used too:

awk -- 'NR > 20' /etc/passwd
Johannes Schaub - litb
  • 481,675
  • 123
  • 870
  • 1,191
3

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

Rotem
  • 442
  • 2
  • 8