• 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 "
    " | cat -A
    SUN08^ISUN09^ISUN10$
    aaaaa^Ieeeee^Ikkkkk$
    aaaaa^Iddddd^I88888$
  • 相关阅读:
    关于云计算的大局观
    定制WPF中的DataGrid控件支持对不同的实体类实现中文标题显示
    优化网站设计(二):使用CDN
    MVVM实践中的Command与CommandParameter的使用
    设计对浏览器更加友好的网站——整合搜索功能(针对Google Chrome)
    使用javascript脚本增强SharePoint Survey(调查)的功能
    学习和自我学习
    你应该如何更好地利用搜索引擎
    使用Project Linker实现多个项目中代码文件的链接
    SharePoint 2010 大局观(1~3)
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15025408.html
Copyright © 2020-2023  润新知