zoukankan      html  css  js  c++  java
  • 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$
  • 相关阅读:
    Restful接口传入多参数
    map转换成JSON的3种方式
    项目打包后执行start.sh提示“no such file or directory”解决办法,linux中给文件增加权限
    如何将一个a表a1字段与b表b1字段的笛卡尔积插入到e表中
    get、set方法的取代注释之lombok插件
    推荐 33 个 IDEA 最牛配置转(Java技术栈)
    mysql-----group by 对多个字段进行分组
    mysql获取某段时间内每一天的统计数据
    发票流水号生成方式
    postman之post请求传参
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15025408.html
Copyright © 2011-2022 走看看