This question already has an answer here:

I have a very big text file, about 80GB, and I need to cut a part form it that lies between two given lines. The part I need is not big, and I have not enough space left on the hard drive to do things like:

head -n 10000000 filename > auxiliary_part
tail -n 1000 auxiliary_part > needed_part

How do I do that?

marked as duplicate by Michael Mrozek Apr 5 '15 at 16:38

This question has been asked before and already has an answer. If those answers do not fully address your question, please ask a new question.

sed -n '3,10p' big-file.txt > your-section.txt

Replace 3 and 10 with your range of lines. The sed commands basically says print (p) everything between lines 3 and 10. The -n tells it to do it quietly, otherwise it prints out the input as its reading the file.

  • 8
    Since the OP specifies a large file, if the desired lines are not near the end of the file, then it may also be useful to include a q command so that sed can skip the rest of the file. Something like 3,$p;10q would work and keep you from having to repeat the ending line number. – Chris Johnsen Mar 5 '11 at 4:41

Pipe one to the other:

head -n 10000000 filename | tail -n 1000 > needed_part

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