In emacs, how to strip CR (^M) and leave LF (^J) characters?

Brandon Leiran picture Brandon Leiran · Jul 23, 2009 · Viewed 28.3k times · Source

I am trying to use hexl mode to manually remove some special chars from a text file and don't see how to delete anything in hexl mode.

What I really want is to remove carriage return and keep linefeed characters. Is Hexl mode the right way to do this?

Answer

CantGetANick picture CantGetANick · Dec 10, 2010

No need to find replace. Just use.

M-x delete-trailing-whitespace

You can also set the file encoding through

C-x RET f unix