I have a file with some strings like below for which I want to replace the || with newline using powershell 5.1.
This is || some test || string
I've follow some advices in this thread and I'm trying with these 2 codes
(Get-Content input.txt) -replace '\|\|', '`r`n' | Out-File output.txt
(Get-Content input.txt) -replace '\|\|', '`r`n' | Set-Content output.txt -Force
but I'm getting this output
This is `r`n some test `r`n string
and desired output is
This is
some test
string
How to fix this?
"..."strings (double-quoted aka expandable strings) perform string interpolation, i.e. expansion of variable values, expressions, and escape sequences such as`n, See the linked duplicate and the conceptual about_Quoting_Rules help topic.[System.Environment]::NewLineto make the newline idea far more obvious. you can even assign it to a $Var and use that ... [grin]