What's a good way of extracting say, lines 20 -45 out of a huge text file. Non-interactively of course!
you could try:
As Mahomedalid pointed out,
The -n flag disables the default output. The "20,45" addresses lines 20 to 45, inclusive. The "p" command prints the current line. And the q quits after printing the line.
This is not an answer but can't post it as a comment.
Another (very fast) way to do it was suggested by mikeserv here:
Using the same test file as here and the same procedure, here are some benchmarks (extracting lines 1000020-1000045):
These are by far the fastest solutions and the differences are negligible (for a single pass) (I tried with different ranges: a couple of lines, millions of lines etc).
Doing it without the pipe might offer a significant advantage, however, to an application which needed to seek over multiple ranges of lines in similar fashion, like:
...and only reads the file through the one time.
Since sed and awk were already taken, here is a perl solution:
Or, as pointed out in the comments: