mno*_*tka 5 linux bash grep pipe
ccze是一款优秀的原木着色器。/usr/lib64/ccze问题是,尽管手册中有说明,但 或中没有插件$HOME/.ccze。看起来所有插件都被编译成二进制文件(所以它们实际上不是插件),我无法轻松修改突出显示。
我想实现什么目标?
我需要添加更多图案以红色突出显示。0尤其是被空白包围的单个。由于我无法轻松修改,因此ccze我正在考虑将其与 grep 结合起来:
tail -f `/bin/ls -1td /var/log/updates/index_*.log` | ccze -A | grep --color '\| 0 '
Run Code Online (Sandbox Code Playgroud)
但这不会产生任何输出(挂起?),尽管事实是:
tail -f `/bin/ls -1td /var/log/updates/index_*.log` | grep --color '\| 0 '
Run Code Online (Sandbox Code Playgroud)
正确突出显示零并且:
tail -f `/bin/ls -1td /var/log/updates/index_*.log` | ccze -A
Run Code Online (Sandbox Code Playgroud)
正确突出其余部分。
提问时间
你能帮我修改上面的命令,这样ccze就能grep很好地一起玩吗?或者只是如何自定义ccze-无需重新编译,因此它可以正确突出显示新内容。
我不想看到的答案
ccze)?阅读手册看起来可以使用
-c, --color KEY=COLOR
Set the color of the keyword KEY to COLOR, like one would do in one of the configuration files.
Run Code Online (Sandbox Code Playgroud)
您可能想尝试将 0 设置为 KEY。
更新:
请忽略以上内容。
我知道发生了什么事。首先,这不会挂起。这是因为你正在使用
tail -f
Run Code Online (Sandbox Code Playgroud)
当您删除-f时,它将快速退出, grep 不会返回任何内容。第二件事是为什么你会看到这种行为。这是因为 ccze 使用 ANSI 颜色代码格式化输出。您可以使用 tee 进行测试,例如:
tail `/bin/ls -1td /var/log/updates/index_*.log` | ccze -A | tee my_log
Run Code Online (Sandbox Code Playgroud)
当你打开my_log时,你会发现很多 ANSI 代码,例如我的文件包含:
| 0 Some message
Run Code Online (Sandbox Code Playgroud)
但是,这是使用tee的ccze -A日志:
^[[22m^[[36m|^[[0m^[[22m^[[36m ^[[0m^[[22m^[[37m0^[[0m^[[22m^[[36m ^[[0m^[[22m^[[36mSome^[[0m^[[22m^[[36m ^[[0m^[[22m^[[36mmessage^[[0m^[[22m^[[36m ^[[0m^[[0m
Run Code Online (Sandbox Code Playgroud)
如您所见,不再有| 0字符串。这就是 grep 什么也不返回的原因。如果您不想重新安装 ccze,那么我看不到干净的解决方案,而是在 grep 命令中使用这种奇怪的模式。
更新2:
您也可以尝试使用 sed:
tail `/bin/ls -1td /var/log/updates/index_*.log` | sed -e 's/| 0/\x1b[31m&\x1b[39m/' | ccze -A
Run Code Online (Sandbox Code Playgroud)
但就我而言ccze改变了0的颜色。
还有一个配置文件:
/etc/cczerc
Run Code Online (Sandbox Code Playgroud)
您可以更改数字的颜色等。