Liuw’s Thinkpad

想要赢就先学会输,想要成功就先学会失败

Get rid of ^M in file

leave a comment »

In fact, a ‘^M’ in text file is a carriage return (CR), often introduced by DOS text file format. It’s possible to do a simple substitution to get rid of it.

Easiest way is to use a dedicated tool called `dos2unix’, and yes, there is a corresponding tool called `unix2dos’.

Or, we can use Vim/Emacs to convert it.


(first open file with Vim)
:set ff=unix
:set ff=dos

Or use Vim command line switches.


$ vim +"set ff=unix" +wq $DOS_FILE

In Emacs, just do a substitution. Use C-q C-m to input ^M.

Written by liuw

2010/07/11 at 20:04

Posted in UNIX-like

Tagged with , , ,

Leave a Reply


为了防止恶意的垃圾评论脚本,请输入以下图片里面的数学方程式的答案。
防垃圾评论问题