Trey Darley wrote: > 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? > > As these *are* logs I'm dealing with I have already implemented rotation > frequency. That helps, but I'm still facing performance issues. I'm > specifically looking for input as to whether my sed-based approach can be > improved. > > Because of extremely limited network bandwidth pulling the files off the > wire and processing them on more studly hardware isn't an option. Also, I > cannot install any binaries on these remote systems. Standard POSIX > toolkit is all I've got to work with. :-/ > > Many thanks, y'all! > --Trey > >
Unfortunately, you can't seek based upon line numbers unless the lines are fixed length. If the lines are fixed length, you could do that and save a lot of I/O activity. If the lines are not fixed length you simply have to start at the beginnig, however with something like awk you could at least end early so you don't read (cause I/O) for the whole file. awk 'NR >= 10000 {print}; NR > 13000 {exit}' Or, there's good old. head -13000 file | tail -3000 _______________________________________________ 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/