【发布时间】:2018-08-24 14:16:44
【问题描述】:
我试过这个命令,但它只能在一定程度上起作用。
输入文件内容:
this is begin not sure what is wrong end and why not
命令:
cat file | sed 's/.*begin \(.*\)end/\1/'
输出:
not sure what is wrong and why not
所需的输出(请参阅下面的注释):
not sure what is wrong
- 我的 sed 命令搜索第一个模式和第二个模式,但忽略了第二个模式并打印文本。但是,它也会打印该行的其余部分,
why not。我不想打印第二个模式之后的内容,只打印两个模式之间的内容。我不知道该怎么做。 - 如果同一行有两个
end怎么办?
有人可以提供并解释该命令吗?
【问题讨论】:
-
你可以使用
sed 's/.*begin \(.*\) end.*/\1/' file