Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
"be consistent"
 
PerlMonks  

Re: Removing Carriage returns from text files

by stefan k (Curate)
on Oct 18, 2001 at 17:44 UTC ( #119678=note: print w/ replies, xml ) Need Help??


in reply to Removing Carriage returns from text files

Uhmm,
what's wrong with

perl -pi.bak -e 's/\r//' file(s)
? This is what I always use when d/l'ing code from the Monastery, because dos2unix (and friends) get confused when there is more than one type of EOL in the file(s). Or won't that handy perl-one-liner work in windows?

Update: typo

Regards... Stefan
you begin bashing the string with a +42 regexp of confusion


Comment on Re: Removing Carriage returns from text files
Download Code
Re: Re: Removing Carriage returns from text files
by helgi (Hermit) on Oct 18, 2001 at 18:26 UTC
    Since none of the replies you have received so far actually solves the problem except under certain restricted circumstances, here is a little utility, macorpc2unix that we use here about a million times a day:
    #!/usr/bin/perl -w -i while (<>) {s/\r\n*/\n/g; print;}
    It will convert PC or Mac text files to Unix format. I see that you could rewrite it with a -p swithc and dispense with the while but I will leave that as an exercise.

    Regards,
    Helgi Briem

      we use here about a million times a day:

      But I bet only on *nix boxes, cause it wont work under win32.

      :-)

      Yves
      --
      You are not ready to use symrefs unless you already know why they are bad. -- tadmc (CLPM)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (8)
As of 2014-04-19 03:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (475 votes), past polls