How can I replace newlines using PowerShell?

前端 未结 5 2114
野的像风
野的像风 2020-12-08 18:24

Given test.txt containing:

test
message

I want to end up with:

testing
a message

I think the fol

5条回答
  •  北荒
    北荒 (楼主)
    2020-12-08 19:08

    If you want to remove all new line characters and replace them with some character (say comma) then you can use the following.

    (Get-Content test.txt) -join ","
    

    This works because Get-Content returns array of lines. You can see it as tokenize function available in many languages.

提交回复
热议问题