1

I have two identical files it appears but they are of different sizes. This leads me to the thought that there are special characters within the file i.e ^M

In VI

:set list

Doesn't show the ^M characters but

cat -A

does show the characters.

In addition, VI shows the special ^M characters only when they happen at the end of a line.

What gives?

DuckCowMooQuack
  • 105
  • 1
  • 12
  • 1
    Sounds like the file has mixed unix `\n` and windows `\r\n` line endings. Vi/Vim won't display `^M` if the whole file has windows line endings, but will show them if it's mixed. – Michael Berkowski Jul 07 '14 at 18:54
  • 1
    See also http://stackoverflow.com/questions/811193/how-to-convert-the-m-linebreak-to-normal-linebreak-in-a-file-opened-in-vim I can't remember if calling `dos2unix` on a mixed file will correctly result in a unix-only line ending file but that's worth a try as well. – Michael Berkowski Jul 07 '14 at 18:56

1 Answers1

1

I don't know about vi, but you see the same thing in Vim:

If every line is \r\n-separated, then Vim by default sets fileformat=dos and loads the file accordingly. Since the \r is part of the line separator, it doesn't show up in the editable text. Vim lets you know this happened by showing [dos] in the status bar when the file is loaded.

If you re-read the file as a UNIX file with :e ++fileformat=unix, the \rs will no longer be considered line separators, and you'll start seeing them in the data instead (with or without :set list).

Note: fileformat is a Vim feature, and is not available in vi.

that other guy
  • 116,971
  • 11
  • 170
  • 194