【问题标题】:How to just remove 0x0a but not 0x0d 0x0a?如何只删除 0x0a 而不是 0x0d 0x0a?
【发布时间】:2021-05-20 23:20:26
【问题描述】:

我想删除 NL 字符,而不是 CR 字符后的 NL 字符。 tr 不会这样做。实现这一目标的最佳命令是什么?

【问题讨论】:

    标签: command-line one-liner


    【解决方案1】:

    Perl 可以做到这一点:

    $ od -c file
    0000000   o   n   e  \n   t   w   o  \r  \n   t   h   r   e   e  \n   f
    0000020   o   u   r  \r  \n  \n
    0000026
    
    $ perl -0777 -pe 's/(\A|[^\r])\n/$1/g' file > file.out
    
    $ od -c file.out
    0000000   o   n   e   t   w   o  \r  \n   t   h   r   e   e   f   o   u
    0000020   r  \r  \n
    0000023
    

    【讨论】:

      猜你喜欢
      • 2016-01-17
      • 2016-12-29
      • 1970-01-01
      • 2011-04-15
      • 1970-01-01
      • 2011-08-11
      • 2020-09-13
      • 2023-04-04
      相关资源
      最近更新 更多