by Zushakon at 2013-01-04 05:54:57
Hi,by RichardSiddaway at 2013-01-04 06:27:45
I wrote a command like this one:
Get-Childitem "\$serwer\d$\folder" -filter file.log -Recurse | gc | Select-String -Pattern "word" -list
Now i thought that parametr "-list" gives only first accurence of the word "word" in every file "file.log" but… it does not. I get all the accurence of word "word" in all files "file.log" in my folder where i only need one.
Any help ?
Its because you are using Get-Content to pipe each line of the file to select-string. Each line is seen as a different object so -List is working properlyby Zushakon at 2013-01-04 06:39:33
You can do all of this in select-string
Select-String -Path c:\reports\log*.txt -Pattern "System" -SimpleMatch -List
only shows the first occurrence of the word System in the files
[quote="RichardSiddaway"]Its because you are using Get-Content to pipe each line of the file to select-string. Each line is seen as a different object so -List is working properly
You can do all of this in select-string
Select-String -Path c:\reports\log*.txt -Pattern "System" -SimpleMatch -List
only shows the first occurrence of the word System in the files[/quote]
Big Thank You, works like a charm and thank You for explaining why my wasn’t working correctly.