0

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 :'(

Ablia
  • 143
  • 9
  • How many files are you talking about, and do you require an automated process or would it be acceptable to handle it manually via e.g., Notepad++? – Jeff Zeitlin Oct 18 '19 at 15:28
  • 1
    If you fancy a lot of batch file code for what you'd have expected to be a simple task, then take a look over on [DOSTips](https://www.dostips.com/forum/viewtopic.php?t=3639#p19022). Alternatively, a [PowerShell solution](https://stackoverflow.com/q/44626938) could be offered. – Compo Oct 18 '19 at 15:33
  • I'm pretty sure you're missing the `g` at the end of the `sed` statement to make it global. – SomethingDark Oct 18 '19 at 22:41
  • @JeffZeitlin: there is maybe 10 files, but those are created through a batch script, which will then use&delete them. That's why i need the change to be done in this script. Not through Notepad (this windows doesn't even have Notepad, btw -_- ) @SomethingDark : yeah, in Wiki the `g` wasn't here, but i did try it at first. Sry forgot to mention it here. i did had a look on dos2unix and weirdly, i thought it was only an unix tool. Found it for windos (thanks to @Compo), i'll try it monday. – Ablia Oct 19 '19 at 17:38
  • So, i've tried `dos2unix`. Had to use the `-f` option to force convertion of binary files, and it's working great, thank you. You could post it as an answer, if the `duplicate` thing get off (i did explain why it wasn't. Could have wait for it before marking it duplicate…) – Ablia Oct 21 '19 at 06:55
  • Also, i would like to understand why are those `sed` not working, since they are the answer in most topics on this type of questions. – Ablia Oct 21 '19 at 07:10

0 Answers0