I am trying to replace a line in a text file. Here is my text file and Powershell script
Text File
String^ m5 = ss.FileMD5(a, salt);
if (m5 != "e11621cc4370a5203423cc1d1ee8c2a7") {
return 6; //mismatch
}
Powershell Script
$fl = "G:\tmp\test\test.txt"
$find = "m5 !="
$repl = 'if (m5 != "aaaaaaaa") {'
$content = (Get-Content $fl)
$line = $content | Select-String $find | Select-Object -ExpandProperty Line
if ($line -eq $null) {
"Match Not Found"
exit
} else {
$content = $content | ForEach-Object { $_ -replace $line, $repl }
$content # print replaced content
}
It is always printing old content without replacement.
What the wrong i am doing in this script ?