对付^M

发表于:2007-07-04来源:作者:点击数: 标签:
http://www.vim.org/tips/tip.php?tip_id=145 We can easily correct the dreaded '^M' at the end of our Unix lines, or make files have more than one line in DOS by: To change from CRLF (DOS) to just LF (Unix): :set fileformat= unix :w Or to ch
http://www.vim.org/tips/tip.php?tip_id=145
We
can easily correct the dreaded '^M' at the end of our Unix lines, or make files have more than one
line in DOS by:

To change from <CR><LF> (DOS) to just <LF> (Unix):
:set fileformat=unix
:w

Or to change back the other way:
:set fileformat=dos
:w

It also works for Apple land:
:set fileformat=mac
:w


另一种方法
remove CTRL-M characters from a file in UNIX

Something useful yet many don't know about it:

Using sed (the stream editor)- try this:
sed -e "s/^M//" FileName > NewFileName

To get ^M you hold down the CTRL key, press V then while still holding CTRL, press M.

While using vi:
% vi filename

While in vi and vim, hit : to get into command mode, then type:
:%s/^M//g

While in Emacs, go to the beginning of the document and
Type:
M-x replace-string RET C-q C-m RET RET

where "RET" means press-the-return-key and C-q and C-m mean hold-the-CTRL-key-and press-the-m-(or q)-key.


原文转自:http://www.ltesting.net