Replacing new line with space with powershell

Viewed 11346

Hi so I've been looking into this for a while and nothing I've tried has worked. Forgive me for asking this again, but I cannot replace a new line with a space in powershell

$path = "$root\$filename"
Get-Content $path | % $_.Replace "`r`n"," " | Set-Content "$root\bob.txt" -Force

This is one of the many things I've tried just looking around on this site.

I'm using powershell v3

4 Answers

Try this:

$NewStr = "";
Get-Content $Path -Raw | ForEach {$NewStr += "$_ "}
$NewStr | Set-Content DestinationPath -Force
Related