8

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?

1

2 Answers 2

20
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.

1
  • 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. Commented Mar 5, 2011 at 4:41
8

Pipe one to the other:

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.