So I have been searching a lot and couldn't find anything that wouldn't return me nothing.
I have a code with a variable and I have a file with a lot of lines on it. For example, I have the following file (things.txt):
Ketchup
Mustard
Pumpkin
Mustard
Ketchup
And what I want to take out is the line numbers of "Mustard". Here's the code I'm trying right now
$search="Mustard"
$linenumber=Get-Content things.txt | select-string $search -context 0,1
$linenumber.context
But it actually returns "". Everyone online was about using context but I only want to know the line number of every "Mustard" which are 2 and 4.
Thanks for your help!
Select-String
returns the line number for you. You're just looking at the wrong property. Change your code to:
$search="Mustard"
$linenumber= Get-Content thing.txt | select-string $search
$linenumber.LineNumber
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With