Count lines as soon as files are read

Getting out of memory exceptions when counting a lot of files as they're
read into memory before being counted. Changed so that the file is read
and processed in one operation