I used the below steps to retrieve a string from file
$variable = 'abc@yahoo.com'
$test = $variable.split('@')[0];
$file = Get-Content C:\Temp\file1.txt | Where-Object { $_.Contains($test) }
$postPipePortion = $file | Foreach-Object {$_.Substring($_.IndexOf("|") + 1)}
This results in all lines that contain $test
as a substring. I just want the result to contain only the lines that exactly matches $test
.
For example, If a file contains
abc_def|hf#23$
abc|ohgvtre
I just want the text ohgvtre