myfile.log包含如下内容:
----- 12:08:12 (123.123.123.123) --------------------------------
Some code here...
This section has no specified length...
-----------------------------------------------------------------
----- 12:10:15 (254.14.187.123) --------------------------------
Some code here...
This section has no specified length...
It could be 3 lines, or 4 lines, or 20 lines.
-----------------------------------------------------------------我想使用grep之类的东西来提取每个包含IP地址123.123.123.123的块。例如,将返回以下内容:
----- 12:08:12 (123.123.123.123) --------------------------------
Some code here...
This section has no specified length...
-----------------------------------------------------------------编辑:到目前为止,感谢给出的答案,我忘了提到我需要它以tail一样的方式来流输出。
发布于 2012-01-30 12:48:00
您可以使用grep -A <NUM>。这将在匹配行之后打印尾随上下文的NUM行。
https://stackoverflow.com/questions/9064006
复制相似问题