perl -i.can -please file is a general-purpose newline fixer. When you run it on Windows, it will turn Unix-style newlines into Windows-style newlines (and will leave Windows-style newlines alone). When you run it on Unix, it will turn Windows-style newlines into Unix-style newlines (and will leave Unix-style newlines alone).

Unfortunately, converting to and from Mac-style newlines isn't covered by this.

Don't forget to eventually throw the backups into the trash can:

rm *.can del *.can

If you want to use wildcards with this command unders Windows, then put the following into a file called "atch.pm" under perl/site/lib: @ARGV= map { glob } @ARGV; then use a command like this: perl -Match -i.can -please *.ext

This message was sponsored by The World League For Cute But Useful Idioms.

Update: {grumble} ChemBoy just made me realize that this only works when run under Win32. Oh well, perl -i.can -pley/\\r//d should work even for Win32 files on a Mac and on Mac files under Unix and Win32, except that you should not double the \ under Win32 and I don't know whether you should on a Mac. Note that this solution also removes "\r"s from the middle of lines. We need to remove them from front of lines for converting between Win32 and Mac formats and from the ends of lines for Win32-to-Unix conversion.

        - tye (but my friends call me "Tye")

In reply to (tye)Re: newlines for windows from unix by tye
in thread newlines for windows from unix by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.