dos2unix不转换^ M [英] dos2unix doesn't convert ^M
问题描述
我从Windows 7上运行的程序中将结果导出到文本文件中,并将该文件复制到Xubuntu 14.04上.在终端中,我运行了dos2unix file.txt
,告诉我converting file out_mapqtl.txt to Unix format
.但是,当我用less
查看文件时,我仍然看到Windows的行尾为^ M,并且wc -l
返回我为"0".
I exported results in a text file from a program running on Windows 7, and copied the file on Xubuntu 14.04. In a terminal, I ran dos2unix file.txt
, which tells me converting file out_mapqtl.txt to Unix format
. However, when I look at the file with less
, I still see the Windows end-of-line as ^M, and wc -l
returns me "0".
我尝试了此处所述的几种方法,但均无效果.然后,我在Vim中打开文件,并按照有的说明进行了:%s/\r/\r/g
的操作,效果很好.那么,为什么dos2unix不起作用?有办法避免每次打开Vim吗?
I tried several things described here, but none works. I then opened the file in Vim and did :%s/\r/\r/g
as explained there, which worked fine. So any idea why dos2unix didn't work? Would there be a way to avoid opening Vim every time?
推荐答案
\r
表示回车符,在MAC上不带\n
表示换行符.您确定文件是DOS(\r\n
)格式而不是MAC(\r
)格式吗?
\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
)?
如果VIM确实是唯一可以修复文件的内容,则还可以通过以下方式调用它:
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?
这篇关于dos2unix不转换^ M的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!