彩色的grep - 查看整个文件,高亮匹配 [英] Colorized grep -- viewing the entire file with highlighted matches

查看:149
本文介绍了彩色的grep - 查看整个文件,高亮匹配的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我觉得的grep - 颜色=总是标记是相当有用的。然而,只有grep的打印用火柴线(除非你要求上下文行)。由于每次打印有一个匹配行,高亮并不因为它可以添加尽可能多的功能。

我真的很想的文件,并看到高亮匹配模式整个文件。

是有一些方法,我可以告诉grep来打印每行而无论是否有相匹配的阅读?我知道我可以写一个脚本在文件的每一行中运行的grep,不过我很好奇,这是否是可能的标准的grep


解决方案

 的egrep --color'的模式| $文件

或者如果你坚持使用grep

 的grep --color -E'的模式| $文件

I find grep's --color=always flag to be tremendously useful. However, grep only prints lines with matches (unless you ask for context lines). Given that each line it prints has a match, the highlighting doesn't add as much capability as it could.

I'd really like to cat a file and see the entire file with the pattern matches highlighted.

Is there some way I can tell grep to print every line being read regardless of whether there's a match? I know I could write a script to run grep on every line of a file, but I was curious whether this was possible with standard grep.

解决方案

egrep --color 'pattern|$' file

or if you insist on using grep

grep --color -E 'pattern|$' file

这篇关于彩色的grep - 查看整个文件,高亮匹配的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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