Snehasish
Snehasish

Reputation: 25

How to replace comma with new line

I am getting input like s1,s2,s3,s4.i am writing it to file.

Tried below way :

$ServerList = Get-Content "D:\ServerName.txt"
Clear-Content -Path "D:\ServerName.txt"
[IO.File]::ReadAllText($ServerList) -replace ',',"`r`n" | Out-File "D:\ServerName.txt"

But it is not writing anything.

It should replace comma with newline to bring each server in new line.

Please let me know where i am doing wrong.

Upvotes: 1

Views: 1535

Answers (1)

guiwhatsthat
guiwhatsthat

Reputation: 2434

This oneliner is working for me:

(Get-Content "Path\test.txt") -replace ',',"`r`n" | Out-File "Path\test.txt"

Upvotes: 1

Related Questions