If you are really going to work with text files with several gigabytes, then do not use PowerShell. Even if you find a way to read it, in any case, PowerShell will process a lot of lines more slowly, and you wonβt be able to avoid it. Even simple road cycles, say, for 10 million iterations (quite real in your case):
# "empty" loop: takes 10 seconds measure-command { for($i=0; $i -lt 10000000; ++$i) {} }
UPDATE: If you are still not afraid, try using the .NET reader:
$reader = [System.IO.File]::OpenText("my.log") try { for() { $line = $reader.ReadLine() if ($line -eq $null) { break }
UPDATE 2
There are comments about a possibly more / less short code. There is nothing wrong with the for source code, and this is not pseudo code. But a shorter (shortest?) Reading cycle option
$reader = [System.IO.File]::OpenText("my.log") while($null -ne ($line = $reader.ReadLine())) { $line }
Roman Kuzmin Nov 16 '10 at 8:53 2010-11-16 08:53
source share