linux 中sed命令删除^M

 

001、方法1

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
aaa
bbb
cc
ddd
ee
[root@PC1 test]# cat -A a.txt
aaa^M$
bbb^M$
cc^M$
ddd^M$
ee^M$
[root@PC1 test]# sed 's/\xd//' a.txt | cat -A
aaa$
bbb$
cc$
ddd$
ee$

image

 .

002、

[root@PC1 test]# ls
a.txt
[root@PC1 test]# cat a.txt
aaa
bbb
cc
ddd
ee
[root@PC1 test]# cat -A a.txt
aaa^M$
bbb^M$
cc^M$
ddd^M$
ee^M$
[root@PC1 test]# sed 's/^M//g' a.txt | cat -A   ## ^M使用ctrl + v,然后ctrl + m打出来
aaa$
bbb$
cc$
ddd$
ee$

image

 。

 

posted @ 2026-01-02 00:37  小鲨鱼2018  阅读(8)  评论(0)    收藏  举报