retrieving a line from the middle of a huge file
- From: joshkorn@xxxxxxxxx
- Date: 12 Oct 2006 15:20:57 -0700
For simplicity, let's imagine I have a file with 1000 lines (of varying
lengths). Let's say I want the 500th line. On unix command line, I
do:
head -500 filename | tail -1
and it runs quickly, no problem.
In perl, I do:
for(my $i=0; $i<499; $i++){
<FILE>;
}
my $line = <FILE>;
and it runs comparitively slowly.
Is there some way to have it do it as fast as the system?
Much thanks.
p.s. Actual specs: 100 files at a time, 100M lines each, and I need to
paste together the second column of specified lines into a single file
of matrix format. The specified lines come in chunks: e.g. lines
10,000,000 to 10,099,999, then lines 11,000,000 to lines 11,099,999.
.
- Follow-Ups:
- Re: retrieving a line from the middle of a huge file
- From: kens
- Re: retrieving a line from the middle of a huge file
- From: kmasaniidc
- Re: retrieving a line from the middle of a huge file
- Prev by Date: How to find exact date from a log directory
- Next by Date: Re: nice regular expression
- Previous by thread: How to find exact date from a log directory
- Next by thread: Re: retrieving a line from the middle of a huge file
- Index(es):
Relevant Pages
|