first of all, I've got a reliable search (thanks to some help on Stack Overflow) that checks for occurrences of different strings in a line over many log files.
I've now been tasked to include multiple searches and since there are about 20 files and about a dozen search criteria, I don't want to to have to access these files over 200 times. I believe the best way of doing this is in a array, but so far all methods I've tried have failed.
The search criteria is made up of date, which obviously changes very day, a fixed string (ERROR) and a unique java classname. Here is what i have:
$dateStr = Get-Date -Format "yyyy-MM-dd"
$errword = 'ERROR'
$word01 = [regex]::Escape('java.util.exception')
$pattern01 = "${dateStr}.+${errword}.+${word01}"
$count01 = (Get-ChildItem -Filter $logdir -Recurse | Select-String -Pattern $pattern01 -AllMatches |ForEach-Object Matches |Measure-Object).Count
Add-Content $outfile "$dateStr,$word01,$count01"
the easy way to expand this is to have a separate three command entry (set word, set pattern and then search) for each class i want to search against - which I've done and it works, but its not elegant and then we're processing >200 files to run the search. I've tried to read the java classes in from a simple text file with mixed results, but its the only thing I've been able to get to work in order to simplify the search for 12 different patterns.
S-Scall? ///// also, the-Pathparameter ofS-Swill read lines in far faster than usingG-Cand a pipeline stage. [grin]-PatternofSelect-Stringsupports a string array. Try this:'One Two Three' |Select-String -Pattern 'One', 'Three', and this:'Two Three Four' |Select-String -Pattern 'One', 'Three'(Either of the two search patterns matches both input lines.) In other words, you can just do:... |Select-String -Pattern $pattern01, $pattern02, $pattern03(which means: select the string that matches$pattern01or$pattern02or$pattern03.