Shell命令从文本文件中去除^ M个字符 [英] Shell command to strip out ^M characters from text file

查看:572
本文介绍了Shell命令从文本文件中去除^ M个字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述


可能存在重复:

在Unix中删除回车


我正在读取一些数据由外部第三方生成。我注意到文件中的ASCII文本中散布着^ M个字符,我认为它是ASCII中的字符13,并且表示没有换行的回车。



我可以使用一个班轮从文件中去除^ M个字符?



我在Linux(Ubuntu)上运行。



  sed -i。 bak's / ^ M $ //'infile.txt 

输入 ^ M ,您需要输入 CTRL-V ,然后输入 CTRL-M


Possible Duplicate:
Remove carriage return in 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.

Is there a one liner I can use to strip the ^M characters from the file?

I am running on Linux (Ubuntu).

解决方案

You can use sed like this:

sed -i.bak 's/^M$//' infile.txt

To type ^M, you need to type CTRL-V and then CTRL-M.

这篇关于Shell命令从文本文件中去除^ M个字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆