本文介绍了使用SED从文件中删除^ M字符的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个文件中这一行:
ULNET-PA,client_sgcib,broker_keplersecurities
开普勒
我试图摆脱了^ M(行)性格让我用:
SED的/ ^ M // G'
不过这并删除一切后,^ M:
[根@本地TMP]#vi测试
ULNET-PA,client_sgcib,broker_keplersecurities ^ M,开普勒[根@本地TMP]#SED的/ ^ M // G'试验
ULNET-PA client_sgcib,broker_keplersecurities
我想获得的是:
[根@本地TMP]#vi测试
ULNET-PA,client_sgcib,broker_keplersecurities,开普勒
解决方案
使用 TR
:
TR -d'^ M'< inputfile中
(请注意, ^ M
字符可以使用输入按Ctrl + V 按Ctrl + M )
编辑:<一href=\"http://stackoverflow.com/questions/19406418/remove-m-characters-from-file-using-sed/19406498?noredirect=1#comment28766761_19406498\">suggested由的,如果你使用庆典
,你还可以说:
TR -d $'\\ r'&LT; inputfile中
I have this line inside a file:
ULNET-PA,client_sgcib,broker_keplersecurities
,KEPLER
I try to get rid of that ^M(newline) character so I used:
sed 's/^M//g'
However this does remove everything after ^M:
[root@localhost tmp]# vi test
ULNET-PA,client_sgcib,broker_keplersecurities^M,KEPLER
[root@localhost tmp]# sed 's/^M//g' test
ULNET-PA,client_sgcib,broker_keplersecurities
What I want to obtain is:
[root@localhost tmp]# vi test
ULNET-PA,client_sgcib,broker_keplersecurities,KEPLER
解决方案
Use tr
:
tr -d '^M' < inputfile
(Note that the ^M
character can be input using )
EDIT: As suggested by Glenn Jackman, if you're using bash
, you could also say:
tr -d $'\r' < inputfile
这篇关于使用SED从文件中删除^ M字符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!