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,
$info = Get-Content -Path $TextFile | Select-Object -Index $from,$to
foreach ($line in $info)
{
,,,
But it does not work. It is like if it only gets the first line in the subset.
I don't find documentation about the Index attribute, so is this possible or should I try using a different approach considering the file size?
The below is working for me. It extract all the content between 2 lines.
Are the rows of fixed length? If they are, you can seek to desired position by simply calculating
offset*row length
and using something like .NetFileStream.Seek()
. If they are not, all you can do is to read file row by row.To extract lines m, n, try something like
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:
Try this code:
The Get-Content cmdlet has a readcount and totalcount parameters. I would play around with those and try to set it up so that the lines your interested in get assigned to an object, then use that object for your loops.