I have the following text file
testA=foo
testB=foobar
testC=Whatever
Now I want to extract the value for testB
which is foobar
. With my current PowerShell command I can only receive the whole line:
testB=foobar
My command is:
Select-String -Path .\test.txt -Pattern "testB=" -List
I could see that there is replace function for strings, so that you could replace testB=
with empty string, but I do not know how to achieve this.
You don't have to replace anything to capture the value. Instead, add a capture group to your search pattern. Then you are able to access the captured value:
(Select-String -Path $scripts.tmp -Pattern "testB=(.*)").Matches.Groups[1].Value
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