[UCLA-LUG] Getting rid of "^M"s in vi

Frederick Lee phaethon@fire.csua.ucla.edu
Sat, 8 Jul 2000 21:43:27 -0700


On Fri, 7 Jul 2000 15:33:45 -0700 (PDT), said "CHEN,THOMAS" <thinking@ucla.edu>:
>I'm editing a text file that displays a lot of "^M" instead of carriage
>returns.  How do I get vi to interpret and display them as such?
>
>-thomas

If it's a bunch of '^M's at the end of lines, it's a MSDOS text format.

The line terminator in MSDOS is CRLF, a CR (Carriage Return, '\r', '^M',
ASCII 13) followed by a LF (Line Feed, '\n', '^J', '^@', ASCII 10).


In Unix, it's just a plain LF.


If it's a bunch of '^M's on one big humoungous line (no line breaks), it's
a Mac text format.

Mac text format, like UNIX, uses a single character for line termination, but
instead of the saner standalone LF, it's a solitary CR instead.


For the MSDOS format, wipe it out (others have pointed it out).

For Mac format, :s/\r/\n/g
Or any other means to convert a CR into a LF.

(e.g. pipe it through "tr '\r' '\n'", e.g. "tr '\r' '\n' < foo > bar")


-Fred