Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

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

2 Answers 2

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

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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