I have a ASCII file generated by Visual Studio that has inconsistent line endings and there is some character values that are > 127 in it.
I'd like to read in the file, perform a regex replace on the text (ignoring character values > 127) and then write the file back without changing the line endings or the characters of a value > 127.
The best that I have is:
(Get-Content $rcFile) -replace
"(FILEVERSION\s+|VALUE\s+`"(?:FileVersion|ProductVersion)`",\s+(`"))$old_major([,.])$old_minor2(?:\3)$old_minor1(?:\3)0",
"`${1}$new_major`${3}$new_minor2`${3}$new_minor1`${3}0" | Set-Content "$rcfile.new"
But the line endings are not as they were. There's a stray \r
near the beginning and near the end that get converted to a \r\n
with this. I'd like to keep this as it was as it keeps being kicked back in by the VS environment and it causes the file to be checked out for no reason.
Is this a lost cause?