Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Replace a character with new line

Powershell ver 4. Windows 7

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

(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 tried double quotes instead of single.

Replace(',',"`n")
like image 658
bobby789 Avatar asked Aug 23 '16 14:08

bobby789


2 Answers

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.

like image 117
autosvet Avatar answered Nov 14 '22 15:11

autosvet


This worked for me.

(Get-Content C:\Test\Test.txt) -replace ',',"`n" | Set-Content C:\Test\Test.txt -Force
like image 21
Shawn Esterman Avatar answered Nov 14 '22 16:11

Shawn Esterman