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

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

    PS> help select -param index
    
    -Index 
        Selects objects from an array based on their index values. Enter the indexes in a comma-separated list.
    
        Indexes in an array begin with 0, where 0 represents the first value and (n-1) represents the last value.
    
        Required?                    false
        Position?                    named
        Default value                None
        Accept pipeline input?       false
        Accept wildcard characters?  false
    

    Based on the above, '8,13' will get you just two lines. One thing you can do is pass an array of numbers, you can use the range operator:

    Get-Content -Path $TextFile | Select-Object -Index (8..13) | Foreach-Object {...}
    

提交回复
热议问题