0

I have two "identical" files that I compare in diff, and it shows that every line is different, after looking at the file I found that one of them has ^M at the end of every line. How do I remove this? I tried this sed command:

sed -i '' -E 's/^M//g'

this tr command: (which even if it worked I wouldn't want since I want to do in place editing)

tr -d '^M'

and this perl command:

perl -pi -e 's/^M//g'

But none of those changed the contents.

DisplayName
  • 11,688

1 Answers1

0

Some time ago I've found these functions in kenrob's .vimrc in his dotfiles repository:

" Removes the ^M character from the end of every line
function! RemoveM()
    :%s/^M$//ge
endfunction

" Replaces the ^M character with a carraige return native to the system
function! ReplaceM()
    :%s/^M/\r/ge
endfunction

So you can easily adopt these functions and use Vim to deal with those ^M characters.