What if some file contains strings like
11111111111111
22222222222222
33333333333333
44444444444444
22222222222222
33333333333333
22222222222222
11111111111111
and I need to find and replace 22222222222222 to 777777777777777 just 2 times while processing the file string by string using foreach and save file with changes after that.
$file = 'path_to\somefile.txt'
foreach($string in $file)
{
$new_string = $string -replace '22222222222222', '777777777777777'
}
$string | Out-file $file
I understand that the script above will replace all strings and will be saved just with one string instead of my requirements.