mba*_*off 1 linux awk command-line grep text
考虑一对关键字:a start-word和a stop-word.是否有任何命令行Linux工具类似于grep或awk打印文本文件中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** '开始单词.
awk '/begin-message/{ P=1; next } /end-message/ {exit} P' new.txt
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
92 次 |
| 最近记录: |