Hello, I need to count the number of lines in a large number of UNIX text files, most of which are fairly large. I need help coming up with an efficient implementation of a line-count program. A naive implementation like length(readlines("foo.txt")) is very slow (notice how this loads the whole file into memory just to count newlines). I imagine that it should be possible to count the number of newline characters quickly, like what the "wc" command does, but I can't figure out how. Does anyone have any ideas?
Thanks for the help. Daniel.