加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 综合聚焦 > 服务器 > 安全 > 正文

What is `^M` and how do I get rid of it?

发布时间:2020-12-15 22:54:35 所属栏目:安全 来源:网络整理
导读:When I open the file in vim ,I am seeing strange ^M characters. Unfortunately,the world‘s favorite search engine does not do well with special characters in queries,so I‘m asking here: What is this ^M character? How could it have gotten

When I open the file in vim,I am seeing strange ^M characters.

Unfortunately,the world‘s favorite search engine does not do well with special characters in queries,so I‘m asking here:

  • What is this ^M character?

  • How could it have gotten there?

  • How do I get rid of it?

he ^M is a carriage-return character. If you see this,you‘re probably looking at a file that originated in the DOS/Windows world,where an end-of-line is marked by a carriage return/newline pair,whereas in the Unix world,end-of-line is marked by a single newline.

A simpler way to do this is to use the following command:(需要安装该工具:yum install dos2unix)
dos2unix filename
This command works with path patterns as well,Eg
dos2unix path/name*
If it doesn‘t work,try using different mode:
dos2unix -c mac filename
-c Set conversion mode. Where CONVMODE is one of: ascii,7bit,iso,mac with ascii being the default.
?
其它方法:
:e ++ff=dos

The :e ++ff=dos command tells Vim to read the file again,forcing dos file format. Vim will remove CRLF and LF-only line endings,leaving only the text of each line in the buffer.

then

:set ff=unix

and finally

:wq

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读