【发布时间】:2013-10-24 17:52:20
【问题描述】:
我在文件中有这一行:
ULNET-PA,client_sgcib,broker_keplersecurities
,KEPLER
我试图摆脱那个 ^M(回车)字符,所以我使用了:
sed 's/^M//g'
但是这确实会删除 ^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
我想要得到的是:
[root@localhost tmp]# vi test
ULNET-PA,client_sgcib,broker_keplersecurities,KEPLER
【问题讨论】:
-
为什么不在你的表达中使用
\n或\r\n? -
@fedorqui 这不是
^和M,而是^M,IIRC,称为control character。 -
使用 $ tr -d '\015'
file2; mv file2 file1 -
简单的方法是,使用'dos2unix
'