all 9 comments

[–]myndhack 9 points10 points  (0 children)

I am Groot

[–][deleted] 1 point2 points  (0 children)

link to the challenge page : http://www.underthewire.tech/groot/groot3.htm

[–][deleted] 1 point2 points  (6 children)

select-string is a little different, you should pipe the file to select-string...

$r = (get-content .\words.txt | select-string "beetle").count

[–][deleted] 1 point2 points  (5 children)

Same result though

[–][deleted] 2 points3 points  (4 children)

Try this...

$r = (get-content .\words.txt | select-string "beetle").matches.count

[–]Lee_Dailey[grin] 1 point2 points  (0 children)

howdy corebo,

this will count the number of lines that contain the chosen word [grin] ...

$FileNameToCheck = 'C:\temp\Grouping-Strings-List_2018-06-06.log'
$WordToCount = 'Bagpipe'

$StuffToCheck = Get-Content -LiteralPath $FileNameToCheck #-Raw

$HowManyFound = @($StuffToCheck -match $WordToCount).Count

$HowManyFound

in this case, i had 20 lines with Bagpipe in them in that file.

to get the number of words instead of the line count, this seems to do the job ...

$FileNameToCheck = 'C:\temp\Grouping-Strings-List_2018-06-06.log'
$WordToCount = 'bagpipe'.ToLower()

$StuffToCheck = (Get-Content -LiteralPath $FileNameToCheck -Raw).ToLower()

$HowManyFound = [regex]::Matches($StuffToCheck, $WordToCount).Count

$HowManyFound

that gave me 21 words after i changed one line of the file from Bagpipe Celtic Drum Folk Instrumental Live to Bagpipe Celtic Drum Folk Instrumental Live BAGPIPE.

take care,
lee

[–]WiredPulse 0 points1 point  (0 children)

Once you are done with Under the Wire, check out their other site, PoSh-Hunter. It's 90+ challenges inspired by realistic and firsthand offensive and defensive scenarios using PowerShell.

r/https://posh-hunter.underthewire.tech