convert CRLF file to LF in windows batch

3k Views Asked by At

i am creating files in Windows, so they're automatically created as CRLF files; i need them to be LF files.

The files are created by a batch script, which then use them and delete them afterward, so I need the change to be done in the batch script, so i can't use the answer given in Change EOL on multiple files in one go. I'm working with MinGW64, so no PowerShell either, which means Powershell v2: Replace CRLF with LF can't solve my problem either. I really need it to be done in a batch script through MinGW64 cmd.

I thought it would be easy to just delete the CR part with a sed, but i've tried all ways i could think about and all i found on the internet, none of them work.

I've tried those:

sed -e "s/\x0d$//" myCRLFfile > newLFfile
sed -e "s/\x0D$//" myCRLFfile > newLFfile
sed -e "s/\r$//" myCRLFfile > newLFfile
awk "{gsub(\""\r\"";\""\"");print} myCRLFfile > newLFfile

I've also tried escaping $ and \ characters with ^. I'va also tried all sed without double quotes (but not with single ones, doesn't work in cmd). All of those are "working", i mean there's no error. They just do Nothing, the CR is still here.

I've even tried doing an hexdump of the file, then do a sed s/0d// of this file, but NO, those 0djust Don't want to delete!

Any idea? I'm struggling on this "expected easy" thing :'(

0

There are 0 best solutions below