0

Is it possbilbe to exit Select-String after 100 matches so that it does not have to read until the end of the text file?

I want to get a sample of matches that is only first 100 matches.

Is there a way to achieve this?

pencilCake
  • 51,323
  • 85
  • 226
  • 363

1 Answers1

2

Try this. You probably could use a Do-Until loop or a for loop and increment a counter then break the loop once you reach the desired number.

$q = Get-Content 'C:\docs\qqq.txt'

$q | Select-String -Pattern "(Patching)" | Select -first 100
user4317867
  • 2,397
  • 4
  • 31
  • 57