linux系统中如何删除^M

1、测试数据

[root@centos79 test]# cat -A a.txt
SUN08^ISUN09^ISUN10^M$
dddd^I33333^Icdddd^M$
dddd^I11111^I55555^M$

 

2、dos2unix删除

[root@centos79 test]# cat a.txt
SUN08   SUN09   SUN10
dddd    33333   cdddd
dddd    11111   55555
[root@centos79 test]# dos2unix a.txt
-bash: /usr/bin/dos2unix: No such file or directory

 

[root@centos79 test]# dnf install dos2unix -y
Last metadata expiration check: 1:51:03 ago on Sun 18 Jul 2021 09:26:03 AM CST.
Dependencies resolved.
=====================================================================================================================================
 Package                         Arch                          Version                             Repository                   Size
=====================================================================================================================================
Installing:
 dos2unix                        x86_64                        6.0.3-7.el7                         base                         74 k

Transaction Summary
=====================================================================================================================================
Install  1 Package

Total download size: 74 k
Installed size: 190 k
Downloading Packages:
dos2unix-6.0.3-7.el7.x86_64.rpm                                                                      126 kB/s |  74 kB     00:00
-------------------------------------------------------------------------------------------------------------------------------------
Total                                                                                                 50 kB/s |  74 kB     00:01
Running transaction check
Transaction check succeeded.
Running transaction test
Transaction test succeeded.
Running transaction
  Preparing        :                                                                                                             1/1
  Installing       : dos2unix-6.0.3-7.el7.x86_64                                                                                 1/1
  Verifying        : dos2unix-6.0.3-7.el7.x86_64                                                                                 1/1

Installed:
  dos2unix-6.0.3-7.el7.x86_64

Complete!

 

[root@centos79 test]# cat -A a.txt
SUN08^ISUN09^ISUN10^M$
dddd^I33333^Icdddd^M$
dddd^I11111^I55555^M$
[root@centos79 test]# dos2unix a.txt
dos2unix: converting file a.txt to Unix format ...
[root@centos79 test]# cat -A a.txt
SUN08^ISUN09^ISUN10$
dddd^I33333^Icdddd$
dddd^I11111^I55555$

 

3、sed命令删除

[root@centos79 test]# cat -A a.txt
SUN08^ISUN09^ISUN10^M$
aaaaa^Ieeeee^Ikkkkk^M$
aaaaa^Iddddd^I88888^M$
[root@centos79 test]# sed 's/^M//g' a.txt -i
[root@centos79 test]# cat -A a.txt
SUN08^ISUN09^ISUN10$
aaaaa^Ieeeee^Ikkkkk$
aaaaa^Iddddd^I88888$

 

4、vi/vim命令删除

命令模式下输入:1,$ s/^M//g

 

5、tr删除

[root@centos79 test]# cat -A a.txt
SUN08^ISUN09^ISUN10^M$
aaaaa^Ieeeee^Ikkkkk^M$
aaaaa^Iddddd^I88888^M$
[root@centos79 test]# cat a.txt | tr -d "\r" | cat -A
SUN08^ISUN09^ISUN10$
aaaaa^Ieeeee^Ikkkkk$
aaaaa^Iddddd^I88888$

 

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。