Get all lines containing a string in a huge text file - as fast as possible?

后端 未结 5 851
伪装坚强ぢ
伪装坚强ぢ 2021-02-05 09:04

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) ?

5条回答
  •  [愿得一人]
    2021-02-05 09:20

    Have you tried using [System.IO.File]::ReadAllLines();? This method is more "raw" than the PowerShell-esque method, since we're plugging directly into the Microsoft .NET Framework types.

    $Lines = [System.IO.File]::ReadAllLines();
    [Regex]::Matches($Lines, 'my_string_pattern');
    

提交回复
热议问题