This seems simple enough but cannot get anything I try to work. I am trying to remove the CRLF from the ends of lines that don't meet my criteria, then output the file to an new file. For example this section:
One~Two~Three~Four
Test Plan Pay Work~scheduled payment pending~79f1cf6e~3/8/2020 6:13:07 PM
Test Plan Pay Work~Bad Request~680a0bb2~3/8/2020 6:14:00 AM
Test Plan Pay Work~GetCardInfo
{failed to validate card
}
~f124a822-aa8d-4624-bb8c-ddsfgdfcc21fb~3/8/2020 6:14:31 PM
Test Plan Pay Work~Bad Request~680a0bb2~3/8/2020 6:14:00 AM
Should output to look like:
One~Two~Three~Four
Test Plan Pay Work~scheduled payment pending~79f1cf6e~3/8/2020 6:13:07 PM
Test Plan Pay Work~Bad Request~680a0bb2~3/8/2020 6:14:00 AM
Test Plan Pay Work~GetCardInfo {failed to validate card}~f124a822~3/8/2020 6:14:31 PM
Test Plan Pay Work~Bad Request~680a0bb2~3/8/2020 6:14:00 AM
Being a newbie I have tried:
Get-Content "C:\temp\errors.csv" | ForEach-Object {
if ((!$_.EndsWith("AM") -and !$_.EndsWith("PM") -and !$_.EndsWith("Four")))
{
$_ -replace ("`r`n",' ')
}
} | Out-File C:\temp\errors2.csv
But this does not work. Any ideas on this? Seems simple but cannot get it to work whatever I try.