I need to replace all the CR(\r) LF(\n) characters (0d 0a in hex) with only LF in a text file ON WINDOWS. In other words, I want to convert a Windows text file to a Unix text file format using Perl...BUT from a Window system, NOT a UNIX system. Simply trying to replace the CR in a substitution string doesn't work. Windows seems to be working against me in that it always puts the CR back with the LF when I do a replace and write the file. A substitution like s/\s+$/\n/; does work, but removes too much because it also removes the LF characters, which I need. I found a few related solutions poking around the Web, but unfortunately, they were intended for execution on UNIX (for example, perl -p -e 's/\r$//' < winfile.txt > unixfile.txt ). Does anyone know of a Windows code solution, or will I need to do something more drastic like edit the binary? Thanks in advance for any assistance. -- New Group member

In reply to Remove CR from file on Windows by kp

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.