> From: discuss-boun...@lopsa.org [mailto:discuss-boun...@lopsa.org] On
> Behalf Of Trey Darley
> 
> Say you've got a simple ascii text file, say, 250,000 lines long. Let's
> say it's a logfile. Suppose that you wanted to access an arbitrary
> range
> of lines, say, lines 10,000 - 13,000. One way of doing this is:
> 
> <snip>
> sed -n 10000,13000p foobar.txt
> </snip>
> 
> Trouble is, the target systems I need to exec this on are ancient and
> don't take very kindly to the io hammering this delivers. Can you
> suggest
> a better way of achieving this?

Inside a process, the process can seek() to a specific byte number in a
file, but if you're looking for a specific range of line numbers, and the
line length is variable, then there's no way to jump directly to a specific
line number.  The only option is to do as you're doing - read from the
beginning of the file, and scan for \n characters and count line numbers.

It's possible, maybe, that sed has an inefficient algorithm to do this.  But
I doubt it.

Unless you can get the data and the workload to be on the same machine ...
or you can find a way to specify a byte range instead of a line number range
... I don't think you're going to gain much over sed.

_______________________________________________
Discuss mailing list
Discuss@lopsa.org
http://lopsa.org/cgi-bin/mailman/listinfo/discuss
This list provided by the League of Professional System Administrators
 http://lopsa.org/

Reply via email to