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

后端 未结 5 852
伪装坚强ぢ
伪装坚强ぢ 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:36

    Have you tried:

    gc myfile.txt | % { if($_ -match "my_string") {write-host $_}}
    

    Or, you can create a "grep"-like function:

    function grep($f,$s) {
        gc $f | % {if($_ -match $s){write-host $_}}
        }
    

    Then you can just issue: grep $myfile.txt $my_string

提交回复
热议问题