In Powershell, how to read and get as fast as possible the last line (or all the lines) which contains a specific string in a huge text file (about 200000 lines / 30 MBytes) ?
$reader = New-Object System.IO.StreamReader("myfile.txt") $lines = @() if ($reader -ne $null) { while (!$reader.EndOfStream) { $line = $reader.ReadLine() if ($line.Contains("my_string")) { $lines += $line } } } $lines | Select-Object -Last 1