【问题标题】:Remove trailing string删除尾随字符串
【发布时间】:2015-04-03 19:11:08
【问题描述】:

在 bash 脚本中,我使用以下命令从文件的最后一行删除尾随 \r\n

# Copy the new last line but remove trailing \r\n
tail -1 $TMPOUT | perl -p -i -e 's/\r\n$//' >>$TMPOUT.1

它目前正在使用 Perl 来关闭 \r\n,但我需要运行它的目标系统没有 Perl 或任何其他脚本(uClinux/Busybox 嵌入式设备)。

如何在“纯”bash 中实现同样的效果?

【问题讨论】:

    标签: linux bash terminal command


    【解决方案1】:

    这个sed 应该可以工作:

    sed -i.bak -n $'$s/\r$//p' "$TMPOUT"
    

    【讨论】:

      【解决方案2】:

      然后使用tr 命令,

      tail -1 $TMPOUT|tr -d '\r\n'
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2018-06-05
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-08-12
        相关资源
        最近更新 更多