in reply to Line Ending Converter

A possible problem here is that you are only converting \015\012 and \012\015, which works for UNIX->Mac|Win32, but not the other way around. Just a minor nit.

You can also do this from the command line:

perl -pi -e 's![\012\015]{1,2}!$/!g' file
Of course, using $/ means you need to be on the desired final OS, but change that to whatever you want it to be.

Replies are listed 'Best First'.
(warning) Re: RE: Line Ending Converter
by bikeNomad (Priest) on Jun 04, 2001 at 19:52 UTC
    The code:

    perl -pi -e 's![\012\015]{1,2}!$/!g' file

    will not work right for mac->unix, mac->dos or unix->mac, because two consecutive \015 or \012 chars will be converted into single ones. So if you have blank lines, they'll get eaten. A safer alternative (though perhaps not an optimal RE) is:

    perl -pi -e 's!(?:\015\012?|\012)!$/!g' file

    update: added safer alternative, made RE 17% faster

RE: RE: Line Ending Converter
by kayos (Sexton) on Jun 16, 2000 at 00:02 UTC
    I get confused. Is a return in a DOS text file \012\015 or \015\012? T.R. Fullhart, kayos@kayos.org
      I use a little mnemonic device to remember this: "DOS is DOA". Well, actually, 0D0A, which converted to octal, is obviously \015\012.

      I use another mnemonic for \r\n. Because \n\r is not right :-)

         MeowChow                                   
                     s aamecha.s a..a\u$&owag.print
        DOS Lives!
        Actually, DOShacker was my old handle but the connotation has changed quite a bit.
        Of course this was before I discovered 'NIX.

        -Lee

        "To be civilized is to deny one's nature."