I have some shell scripts created on windows I want to run dos2unix
on them.
But as I have read that dos2unix
works in Linux
In PowerShell there are so many solutions, given a lot of tools in the .NET platform
With a path to file in $file = 'path\to\file'
we can use
[IO.File]::WriteAllText($file, $([IO.File]::ReadAllText($file) -replace "`r`n", "`n"))
or
(Get-Content $file -Raw).Replace("`r`n","`n") | Set-Content $file -Force
To do that for all files just pipe the file list to the above commands:
Get-ChildItem -File -Recurse | % { (Get-Content -Raw `
-Path $_.Fullname).Replace ("`r`n", "`n") | Set-Content -Path $_.Fullname }
See
For bigger files you may want to use the buffering solutions in Replace CRLF using powershell