Replace a character with new line

不打扰是莪最后的温柔 提交于 2020-01-03 15:19:34

问题


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")

回答1:


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.




回答2:


This worked for me.

(Get-Content C:\Test\Test.txt) -replace ',',"`n" | Set-Content C:\Test\Test.txt -Force


来源:https://stackoverflow.com/questions/39104275/replace-a-character-with-new-line

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!