【问题标题】:Basic Grepping/Sedding a part of output基本 Grepping/Sedding 输出的一部分
【发布时间】:2014-04-25 23:04:10
【问题描述】:

我需要删除“+0x10”部分,但数字可能会改变(更多数字),所以我不能总是从后面删除 5 个字符。

something -- printf@plt+0x10

模式总是“plt+”,然后是一个十六进制数字。我希望它看起来像这样:

something -- printf@plt

只是没有“+0x10”。我是 bash 初学者,所以请耐心等待。

【问题讨论】:

    标签: bash sed scripting grep


    【解决方案1】:

    你可以使用 bash substring removal:

    $ string="something -- printf@plt+0x10"
    $ echo "${string%+*}"
    something -- printf@plt
    

    【讨论】:

      【解决方案2】:

      参数替换可以这样做:

      $ my_var="printf@plt+0x10"
      $ echo "${my_var%%+0*}"
      printf@plt
      

      【讨论】:

        【解决方案3】:

        你可以使用:

        s='something -- printf@plt+0x10'
        sed 's/^\(.*\)+0x[0-9]*$/\1/' <<< "$s"
        something -- printf@plt
        

        【讨论】:

        • 很高兴知道,您能否通过单击我的答案左上角的勾号将答案标记为已接受。
        猜你喜欢
        • 2013-09-23
        • 2020-04-30
        • 1970-01-01
        • 2018-12-13
        • 1970-01-01
        • 2015-02-10
        • 1970-01-01
        • 1970-01-01
        • 2021-08-18
        相关资源
        最近更新 更多