命令行工具,用于打印某些匹配关键字之间的所有字符

mba*_*off 1 linux awk command-line grep text

考虑一对关键字:a start-word和a stop-word.是否有任何命令行Linux工具类似于grepawk打印文本文件中a start-word和a 之间的所有行stop-word

例如,一个文本文件:

header
blah-blah
blah
begin-message
message content line 1
message content line 2
end-message
footer
blah-blah
blah

通过start-word将'begin-message' 指定stop-word为'end-message',预期输出应为:

消息内容行1
消息内容行2

编辑:开始 - 停止 - 单词可能包含不能仅以awk正则表达式模式输入的特殊字符,例如' **BEGIN MESSAGE** '开始单词.

ush*_*sha 6

awk '/begin-message/{ P=1; next } /end-message/ {exit} P' new.txt
Run Code Online (Sandbox Code Playgroud)