Beefy Boxes and Bandwidth Generously Provided by pair Networks Bob
P is for Practical
 
PerlMonks  

RE: Remove the ^M Character from a Document

by ZZamboni (Curate)
on May 08, 2000 at 14:13 UTC ( [id://10606]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to Remove the ^M Character from a Document

On a similar note, the other day I had a postscript file with an embedded pixmap graphic which contained line breaks represented only as "\r", in addition to the usual DOS "\r\n" at the end of each line. The graphic with the \r's came up, in Unix, as a single over-900K line, which broke most programs I tried to use to manipulate the file (those programs were not written in Perl, clearly :-)

So based on this snippet, I came up with the following one-liner:

perl -pi -e 's/\r\n?/\n/g' <i>file</i>
which solved my problem.

Replies are listed 'Best First'.
Re: Remove the ^M Character from a Document
by hacker (Priest) on Jun 03, 2002 at 12:07 UTC
    You might want to try a different substitution character, to lessen the obfuscation on this syntax, such as:
    perl -pi.orig -e 's#\r\n#\n#g' filespec
    or
    perl -pi.orig -e 's,\r\n,\n,g' filespec
    Though ideally, this is more correct:
    perl -pi.orig -e 's,\cM,,g' filespec # commas for clarity
      The use of the forward slash to delimited regular expressions and replacements has a history of decades - predating the birth of Perl by years. There are no forward slashes in the regular expression that could cause confusion. So, other than a fear of forward slashes, what makes you think use of a forward slash contributes to obfuscation?

      Abigail

        Perhaps hacker actually means that the use of another character could make things easier to read. I remember somewhere some book or other refering to the "leaning toothpick" problem.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://10606]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.