基本的Grepping / Sedding是输出的一部分

时间:2014-03-19 15:16:58

标签: bash sed scripting grep

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

something -- printf@plt+0x10

模式始终为“plt +”,然后是十六进制数。我希望它看起来像这样:

something -- printf@plt

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

3 个答案:

答案 0 :(得分:2)

您可以使用:

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

答案 1 :(得分:0)

参数替换可以这样做:

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

答案 2 :(得分:0)

您可以使用bash substring removal

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