bobby789 bobby789 - 1 year ago 130
PowerShell Question

Replace a character with new line

Powershell ver 4. Windows 7

I wanted to replace
with new lines in a text file. I tried below script

(Get-Content C:\Test\test.txt).Replace(',','`n') | Set-Content C:\Test\testv2.txt

but when I see the output file I see
replaced with '`n' instead of new line.

I also tired double quotes instead of single.


Answer Source

Try this:

[IO.File]::ReadAllText(C:\Test\test.txt) -replace ',',"`r`n" | Out-File C:\Test\testv2.txt

P.S. Sorry that don't have time to explain it, now.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download