2

简单的问题,但我的 sed 命令不起作用:(

echo "some_class" | sed -e 's/.+\_\(.+\)/\1/'

我想要恰好在 _ 字符之后的所有内容。请问,我怎样才能修复我的代码工作?谢谢你。

在这种情况下,“类”是正确的答案。

4

2 回答 2

3

You don't need sed; you can use parameter expansion to return the substring beginning with the first _:

foo=some_class
echo "${foo#*_}"
于 2013-07-17T12:09:12.403 回答
3

this sed line works for your example:

sed 's/.*_//'

with your example:

kent$  echo "some_class"|sed 's/.*_//'
class
于 2013-07-17T12:09:20.737 回答