dos2unix doesn't convert ^M

我们两清 提交于 2019-12-03 05:48:59

\r denotes a carriage return, and on MAC it is used without \n to denote a line break. Are you sure the file is in DOS (\r\n) format and not MAC (\r)?

If VIM really turns out to be the only thing that'll repair your files, you can also invoke it as:

vim somefile.txt +"%s/\r/\r/g" +wq

This will open the file, perform the operation, save it, then quit.

Can you give us an example of the file, so that we can investigate further?

I know you have gotten this resolved, but I wanted to add a note for reference, based on some testing I've done.

If less is showing ^M, then like Sybren I suspect it is a MAC style ending (\r), not DOS (\r\n). You can determine that easily using cat:

$ cat -e filename

  • Unix endings (\n) show as $
  • MAC endings (\r) show as ^M (less shows these)
  • DOS\Windows endings (\r\n) show as ^M$ (less does not appear to show these)

Use dos2unix to get rid of the DOS (^M$) endings

Use mac2unix to get rid of the MAC (^M) endings - dos2unix won't get rid of these.

I had a file where I had to use dos2unix and mac2unix to get rid of all the non-Unix endings.

Try this:

tr -d '\r' < file
标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!