Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

RE: Line Ending Converter

by KM (Priest)
on May 20, 2000 at 04:27 UTC ( [id://13805]=note: print w/replies, xml ) Need Help??


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."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://13805]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others scrutinizing the Monastery: (5)
As of 2024-04-24 07:26 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found