View Single Post
Old 06-14-2007   #4 (permalink)
Jacques Barathon [MS]


 
 

Re: Searching large text files

"Kiron" <Kiron@discussions.microsoft.com> wrote in message
news:67AC4B33-13F4-4A00-BD9F-080549674FDE@microsoft.com...
> Use Get-Content's -ReadCount parameter, set it to 1 to send a line at a
> time
> through the pipeline but don't assign this to a variable before, instead
> redirect the output to a file, e.g.:
>
> gc c:\largeFile.txt -read 1 | ? {<filters>} > c:\filteredFile.txt
>
> # don't assign the out to variable like this
> $filterContent = gc c:\largeFile.txt -read 1 | ? {<filters>}


Alternatively you can use the System.IO.File class:

[io.file]::ReadAllLines("c:\largeFile.txt")

It definitely is faster than get-content, it may also make better usage of
memory.

Jacques

My System SpecsSystem Spec