Sugapablo wrote:
file() works great, until you start looking at file that are very large,
say 134MB.
Is there any function that will return an array for each line of a file,
but only for lines given as parameters?
A function like file("/path/to/file",100,230) which would return lines 100
through 230 as an array.
Nope. Have to write it yourself.
There is a lot of lazy ways to do it though. PHP (fopen/fgets), piping
from head to tail, sed, awk, grep.
The shortest to write, given your example, is:
sed -n -e 231q -e 100,+130p '/path/to/file'
But not the best choice for performance in all cases. If you only need
to read a small amount of data from the beginning of the file, then use
fopen/fgets in PHP to fetch the lines you need. Even though PHP is slow
compared to the shell-utils, running shellcommands from PHP is costly
enough to sometimes opt for PHP.
If you need to fetch lines from anywhere in the file, then I think grep
would be better. Not sure how head with tail would perfom, or if some
other tool exist.
Those are the lazy ways. If performance is still a problem, then you
need to do other things.
/Bent