Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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?

share|improve this question

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.

Also consider one of the answers here: unix.stackexchange.com/questions/2072/… – Steven D Mar 5 '11 at 5:17
up vote 19 down vote accepted
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.

share|improve this answer
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
share|improve this answer

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