多种颜色的grep输出? [英] Grep output with multiple Colors?

查看:169
本文介绍了多种颜色的grep输出?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有在运行的grep针对2个或更多的模式的文本文件的bash的一个优雅的方法,以及每个匹配图案是在不同的颜色输出?

Is there a elegant method in bash of running grep against a text file with 2 or more patterns, and each pattern that matches is output in a different color?

因此​​,一个上 MALE匹配行 AUGUST 将出放蓝色和 AUGUST 橙色?
我打开使用 SED AWK 的grep 和蜡笔或其他...

So a line that matches on MALE and AUGUST would out put MALE in blue and AUGUST in orange? I am open to the use of sed, awk, grep and crayons or other...

推荐答案

您可以通过指定--color =始终与使用常规的前pression'富| $'级联用不同的颜色里grep通过所有行。

You can cascade greps with different colors by specifying --color=always and using the regular expression 'foo|$' to pass all lines.

例如:

tail -f myfwlog | GREP_COLOR='01;36' egrep --color=always 'ssh|$' | GREP_COLOR='01;31' egrep -i --color=always 'drop|deny|$'

如果你想突出整条生产线,相应地更新你的常规的前pression:

If you want the entire line to be highlighted, update your regular expression accordingly:

.... GREP_COLOR='01;31' egrep -i --color=always '^.*drop.*$|^.*deny.*$|$'

这篇关于多种颜色的grep输出?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆