Try this:
$txt = (Get-Content -Raw myFile.txt) -replace "`r`n","`n"
[io.file]::WriteAllText('c:\path\to\myFile.unix.txt', $txt)
I used WriteAllText
rather than Set-Content
because Set-Content
adds a carriage return and a line feed to the end of the file, and there doesn't seem to be any way to suppress that.
I think that the -Raw
parameter to Get-Content
might be a PowerShell 3 thing, so if you are using an earlier version, you might need to do it like this:
$txt = [io.file]::ReadAllText('c:\path\to\myFile.txt') -replace "`r`n","`n"
[io.file]::WriteAllText('c:\path\to\myFile.unix.txt', $txt)