Efficient way to get n middle lines from a very big file Efficient way to get n middle lines from a very big file unix unix

Efficient way to get n middle lines from a very big file


With sed you can at least remove the pipeline:

sed -n '600000,700000p' file > output.txt

will print lines 600000 through 700000.


awk 'FNR>=n && FNR<=m'

followed by name of the file.


It might be more efficient to use the split utility, because with tail and head in pipe you scan some parts of the file twice.

Example

split -l <k> <file> <prefix>

Where k is the number of lines you want to have in each file, and the (optional) prefix is added to each output file name.