http://www.perlmonks.org?node_id=119678


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

Replies are listed 'Best First'.
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)