Get a subset of lines from a big text file using PowerShell v2

后端 未结 5 798
终归单人心
终归单人心 2020-12-30 11:57

I\'m working with a big text file, I mean more than 100 MB big, and I need to loop through a specific number of lines, a kind of subset so I\'m trying with this,

<
5条回答
  •  自闭症患者
    2020-12-30 12:38

    Try this code:

    Select-String $FilePath -pattern "FromHere" | Out-Null
    
    $FromHereStartingLine = Select-String $FilePath -pattern "FromHere" | Select-Object LineNumber
    
    $UptoHereStartingLine = Select-String $FilePath -pattern "UptoHere" | Select-Object LineNumber
    
    for($i=$FromHereStartingLine.LineNumber; $i -lt $UptoHereStartingLine.LineNumber; $i+=1)
    {
        $HoldInVariable += Get-Content -Path $FilePath | Foreach-Object { ($_  -replace "`r*`n*","") } | Select-Object -Index $i
    }
    
    Write-Host "HoldInVariable : " $HoldInVariable
    

提交回复
热议问题