I need to create a file with Linux line endings in a Windows command script.
The closest I can get so far is this PowerShell one-liner:
powershell.exe -Command "Get-ChildItem -File "D:\path\file.sh" | % { $x = get-content -raw -path $_.fullname; $x -replace [char[]](13),'' | set-content -path $_.fullname }"
This is so close to what I want... the fly in the ointment is that it adds an extra CR+LF at the end of the file! Any suggestions for how I can fix this, or alternative techniques? I can't install any additional software such as Cygwin or dos2unix as this is for a locked-down production environment.
Set-Content -NoNewline. – mvw Jan 11 '18 at 09:59(Get-Content $file -Raw).Replace("`r`n", "`n") | Set-Content $path -Force– phuclv Aug 07 '21 at 01:36