Linux Shell命令从文本文件中去除^M个字符
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13589895/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Shell command to strip out ^M characters from text file
提问by Homunculus Reticulli
Possible Duplicate:
Remove carriage return in Unix
可能的重复:
在 Unix 中删除回车
I am reading some data generated by an external third party. I have noticed that the ASCII text in the file is interspersed with ^M characters, which I believe is character 13 in ASCII and represents a carriage return without linefeed.
我正在读取外部第三方生成的一些数据。我注意到文件中的 ASCII 文本散布着 ^M 字符,我认为这是 ASCII 中的字符 13,表示没有换行符的回车。
Is there a one liner I can use to strip the ^M characters from the file?
有没有一种衬里可以用来从文件中去除 ^M 字符?
I am running on Linux (Ubuntu).
我在 Linux (Ubuntu) 上运行。
采纳答案by anubhava
You can use sed like this:
您可以像这样使用 sed:
sed -i.bak 's/^M$//' infile.txt
To type ^M
, you need to type CTRL-V
and then CTRL-M
.
要键入^M
,您需要键入CTRL-V
然后CTRL-M
。
回答by shellter
OR
或者
dos2unix infile.txt file2.txt ....
OR
或者
man dos2unix
for more details.
更多细节。