linux - grep 命令在每次匹配后添加结束行

标签 linux shell unix grep

<分区>

你知道如何添加一些结束行吗

"=========================================================================================="

每场比赛结束后

tail -f error.log -n 2000 | grep -B 10 -A 25 'Exception:'

此命令打印所有异常日志,但我喜欢为每个异常日志看到一个分隔线。

最佳答案

您需要以下选项:

--group-separator=SEP
Use SEP as a group separator. By default SEP is double hyphen (--).

演示:

$ cat file
before
exception 1
after
foo
bar
before
exception 2
after

$ grep -A 1 -B 1 --group-separator======================== exception file 
before
exception 1
after
=======================
before
exception 2
after

关于linux - grep 命令在每次匹配后添加结束行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20567667/

相关文章:

c# - 让 Mono 和 Firebird Embedded 在 Linux 上运行

bash - 如何在 bash 中结合 awk 和 if

linux - 案例陈述在我的 shell 脚本中不起作用

c - 在 tmp 文件夹中打开文件时使用信号量不起作用

regex - 如何从 Unix shell 变量中提取与模式匹配的子字符串

linux - 禁用 http 端口上的 telnet?

linux - 使用 gcc.7.2 编译器时,Linux 中的 stdio.h 文件在哪里?

linux - 使用 xargs 将变量传递给别名命令

bash - 将 shell 参数存储在文件中,同时保留引号

unix - 保持点文件跨机器同步?