If you want lines X to Y inclusive (starting the numbering at 1), use

 tail -n +$X /path/to/file | head -n $((Y-X+1))

`tail` will read and discard the first X-1 lines (there's no way around that), then read and print the following lines. `head` will read and print the requested number of lines, then exit. When `head` exits, `tail` receives a [SIGPIPE](http://en.wikipedia.org/wiki/SIGPIPE) signal and dies, so it won't have read more than a buffer size's worth (typically a few kilobytes) of lines from the input file.

Alternatively, as [gorkypl](http://unix.stackexchange.com/questions/47407/cat-line-x-to-line-y-on-a-huge-file/47410#47410) suggested, use sed:

 sed -n -e "$X,$Y p" -e "$Y q" /path/to/file

I expect `tail | head` and sed to have similar performance.

If you know the byte range you want to work with, you can extract it faster by skipping directly to the start position. But for lines, you have to read from the beginning and count newlines. To extract blocks from x inclusive to y exclusive starting at 0, with a block size of b:

 dd bs=$b seek=$x count=$((y-x)) </path/to/file