Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?

How to remove ^M from a file

by Tii (Monk)
on Aug 01, 2000 at 20:41 UTC ( #25499=perlquestion: print w/replies, xml ) Need Help??

Tii has asked for the wisdom of the Perl Monks concerning the following question:

Greetings, Monks...

Please forgive me for asking a redundant question, but before posting this, I searched for the answer to no avail:

How can I replace the ^M found in a file (usually after it has been ftp'ed in binary format instead of ascii)?

Even better, is there a way to delete the lines that contain only ^M?


PS: I remember that this question was asked before and the answer was something that could be done on the command line.

Replies are listed 'Best First'.
Re: How to remove ^M from a file
by Russ (Deacon) on Aug 01, 2000 at 20:46 UTC
RE: How to remove ^M from a file
by DrManhattan (Chaplain) on Aug 01, 2000 at 21:53 UTC
    perl -pi -e 's/\r//g' filename


RE: How to remove ^M from a file (dos2unix)
by ybiC (Prior) on Aug 01, 2000 at 22:17 UTC
    A not-at-all perlish method would be some variation of the *nix command dos2unix.

    A slightly-more-perlish approach might be the Power Ptools equivelent nlcvt.

Re: How to remove ^M from a file
by Tii (Monk) on Aug 01, 2000 at 22:40 UTC
    Thanks to everyone for the help!


Re: How to remove ^M from a file
by Buckaroo Buddha (Scribe) on Aug 02, 2000 at 19:26 UTC

    sorry for the -- but it's my opinion that if you know that
    a question has been asked before then it is more polite to
    either search for that question yourself or ask for help finding
    the link to that question in the chatterbox

    maybe it was wrong of me to do it, but that's the reasoning for it
    if you disagree you can -- me back :) Update:

    on the other hand a 'thank you' post is perfectly acceptable!! (++ ;)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://25499]
Approved by root
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (5)
As of 2020-08-11 07:24 GMT
Find Nodes?
    Voting Booth?
    Which rocket would you take to Mars?

    Results (58 votes). Check out past polls.