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

后端 未结 5 797
终归单人心
终归单人心 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:42

    The below is working for me. It extract all the content between 2 lines.

    $name     = "MDSinfo"
    $MDSinfo  = "$PSScriptRoot\$name.txt" #create text file
    $MDSinfo  = gc $MDSinfo
    
    $from =  ($MDSinfo | Select-String -pattern "sh feature" | Select-Object LineNumber).LineNumber
    $to =  ($MDSinfo  | Select-String -pattern "sh flogi database " | Select-Object LineNumber).LineNumber
    
    $i = 0
    $array = @()
    foreach ($line in $MDSinfo)
    {
    foreach-object { $i++ }
        if (($i -gt $from) -and ($i -lt $to))
        {
        $array += $line      
        }
    }
    $array
    

提交回复
热议问题