how to convert a file from DOS to Unix

judi picture judi · Aug 18, 2015 · Viewed 10.7k times · Source

I need to convert a file from DOS to Unix in PowerShell.

I know this can be very much easily done in Unix:

dos2unix file newfile

Answer

Jower picture Jower · Aug 18, 2015

It could be as simple as

Get-Content in.csv -raw | % {$_ -replace "`r", ""} | Set-Content -NoNewline out.csv

Above method will work on powershell version 3+. If you are below that you can use below method instead. Almost same as one of the other answers here.

$csvdata = [io.file]::ReadAllText('in.csv') | % {$_ -replace "`r",""}
[io.file]::WriteAllLines('out.csv', $csvdata)