in reply to Re: Remove CR from file on Windows
in thread Remove CR from file on Windows

None of those work in Windows. (I presume that's what you meant by DOS.)
>echo Hello > winfile.txt >echo World >> winfile.txt >perl -pe "s/\r(?=\n)//" winfile.txt > unixfile.txt >debug unixfile.txt -rcx CX 0010 : -d100 l10 0AF7:0100 48 65 6C 6C 6F 20 0D 0A-57 6F 72 6C 64 20 0D 0A Hello ..W +orld .. -q

Well, they might work with a simulated unix environment in Windows (like cygwin), but that's an entirely different world.

The earlier posts in this thread not only provided the solution, they explained this problem and the workaround.

If it's one-liners you wanted,

Replies are listed 'Best First'.
Re^3: Remove CR from file on Windows
by davidrw (Prior) on Feb 10, 2007 at 13:19 UTC
    I tested (in a DOS window on WindowsXP, striaght -- no cygwin) all of what i posted .. I don't understand -- why doesn't it work??
    C:\foo>type foo.bat @echo OFF echo "making test file" perl -e "print \"foo\r\nbar\r\nstuff\";" > f.txt echo "showing test file" perl -pe "s/(\s)/'['.ord($1).']'/esg" f.txt echo "altering file" perl -i.bak -pe "s/\r(?=\n)//" f.txt echo "showing result" perl -pe "s/(\s)/'['.ord($1).']'/esg" f.txt C:\foo>foo.bat "making test file" "showing test file" foo[13][10]bar[13][10]stuff "altering file" "showing result" foo[10]bar[10]stuff C:\foo>

      You think your solution works because your script to create the test file and your script to dump the test file suffers from the same bug as your solution. Your demonstration only shows that you can convert CRCRLF to CRLF.

      The first f.txt contains foo\r\r\nbar\r\r\nstuff.

      >perl -e "print \"foo\r\nbar\r\nstuff\";" > f.txt >debug f.txt -rcx CX 0011 : -d100 l11 0AF7:0100 66 6F 6F 0D 0D 0A 62 61-72 0D 0D 0A 73 74 75 66 foo...bar +...stuf 0AF7:0110 66 f -q

      You alter it to foo\r\nbar\r\nstuff.

      >perl -i.bak -pe "s/\r(?=\n)//" f.txt >debug f.txt -rcx CX 000F : -d100 lf 0AF7:0100 66 6F 6F 0D 0A 62 61 72-0D 0A 73 74 75 66 66 foo..bar. +.stuff -q

      why doesn't it work??

      Unless you use binmode on your input file, CRLF gets converted to LF on read.
      Unless you use binmode on your output file, LF gets converted to CRLF on write.