in reply to Perl Regex to Fix line feed issue

moo@cow[1]~>which rnfix rnfix: aliased to perl -pi.bk -e 's/\r\n?/\n/g'

I find it very handy, hence the alias, but use with caution! It's fine for text files. It will break binary files. I added a .bk for the example. Take it out if you're sure you know what you're doing. (update, took out the /g, pretty sure that was just a stupid reflex; update, update: put it back, I need to lie down.)

Replies are listed 'Best First'.
Re^2: Perl Regex to Fix line feed issue
by mmittiga17 (Scribe) on May 09, 2008 at 20:32 UTC
    Thanks to all for their replies. Nothing seems to work. I am trying a different approach. if line ends in ^M and the next starts with ^M join lines. Then remove the ^M^M from middle of the line. Any thoughts?

      untested:

      $/ = "\r\n"; while (<>) { if (s/^\r//) { $l .= $_; $l =~ s/\r\r//g; next; } else { print $l; $l = $_; } } print $l;

      although I don't know what the heck you are wanting to to with what files to what end.

      Could you show what you've tried? and perhaps some sample input?

      --shmem

      _($_=" "x(1<<5)."?\n".q·/)Oo.  G°\        /
                                    /\_¯/(q    /
      ----------------------------  \__(m.====·.(_("always off the crowd"))."·
      ");sub _{s./.($e="'Itrs `mnsgdq Gdbj O`qkdq")=~y/"-y/#-z/;$e.e && print}