0

I have 10k of html files and about 3k of them include youtube video embed code, so i search for the string to get list of those files like this:

$LocalListOfYTPosts = Get-ChildItem "$outputfolder*.html" -recurse |
     Select-String -pattern "https://www.youtube.com/embed" | 
     group path | 
     select name -ExpandProperty Name

Youtube embed code is included only once per file, so i thought that i could speed things up if search will go to next file after 1st occurrence of the string (I'm not sure if that's actually correct)

Is there a way to tell to powershell to go to next file if the string has been found in in the current one?

Eris
  • 7,378
  • 1
  • 30
  • 45
Peter Pavelka
  • 511
  • 1
  • 5
  • 16
  • 1
    Try the `-List` option on `Select-String`: Returns only the first match in each input file. By default, Select-String returns a MatchInfo object for each match it finds. – Eris Jun 26 '16 at 19:12
  • Thanks, that helped a bit, time from 39 seconds dropped to 35 so not a big difference, but every little helps :) – Peter Pavelka Jun 26 '16 at 19:46
  • You could try parallelizing the processing of the files using workflows but as this is mostly IO bound, it might make matters worse. There's nothing lost in trying though. Have a look at [this](http://stackoverflow.com/a/19727899/52598) SO question that can be used as a template. – Lieven Keersmaekers Jun 27 '16 at 05:01

1 Answers1

1

(Comment -> Answer)

Try the -List option on Select-String:

Returns only the first match in each input file. By default, Select-String returns a MatchInfo object for each match it finds.

Eris
  • 7,378
  • 1
  • 30
  • 45