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$
  • 相关阅读:
    request对象
    js基础3
    Andorid Binder进程间通信---总结
    java 获取系统变量(环境变量和设置变量)
    參加项目管理培训的一些体会
    select poll使用
    关注关注工作行列
    jquery——zTree, 完美好用的树插件
    OSI七层模型具体解释
    (原创)优酷androidclient 下载中 bug 解决
  • 原文地址:https://www.cnblogs.com/liujiaxin2018/p/15025408.html
Copyright © 2011-2022 走看看