I have a file with 1 million lines. I want to extract lines from line 10001 to 500000 How to do this?


sed is your friend:

sed -n '10001,500000p;500001q'

Note that 500001q is needed to stop further file processing. Otherwise it will still read the file till the very end. Thanks for hint on this to @Freddy.

  • 1
    Maybe add ;500001q to stop further processing. – Freddy Apr 18 at 13:07
  • Updated the answer. Thx for hint – rush Apr 18 at 13:09

Might as well have a head/tail solution as well:

head -n 500000 yourfile.txt | tail -n +10001

(Somewhat misleadingly, tail -n +10 is different from tail -n 10 – the former starts at line 10, the latter only prints the last 10 lines.)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.