管道grep来后的grep preserve着色 [英] Preserve colouring after piping grep to grep
问题描述
有在 preserve LS grep'ing着色后一个问题simlar 但它惹恼我,如果你管彩色的grep输出到另一个grep,该颜色是不是preserved。
There is a simlar question in Preserve ls colouring after grep’ing but it annoys me that if you pipe colored grep output into another grep that the coloring is not preserved.
例如的grep --color WORD * | grep的-v AVOID
不保持第一输出的颜色。但对我来说 LS | grep的文件
做保持颜色,为什么不同?
As an example grep --color WORD * | grep -v AVOID
does not keep the color of the first output. But for me ls | grep FILE
do keep the color, why the difference ?
推荐答案
写入管道时的grep
有时禁用彩色输出,例如。您可以覆盖这个行为的grep --color =总是
grep
sometimes disables the color output, for example when writing to a pipe. You can override this behavior with grep --color=always
正确的命令行是
grep --color=always WORD * | grep -v AVOID
这是pretty冗长,或者你可以添加行
This is pretty verbose, alternatively you can just add the line
alias cgrep="grep --color=always"
你的的.bashrc
例如,用 cgrep
为彩色的grep。当重新定义的grep
你可能会遇到麻烦,这依赖于的grep
的特定的输出,不喜欢ASCII逃生脚本code。
to your .bashrc
for example and use cgrep
as the colored grep. When redefining grep
you might run into trouble with scripts which rely on specific output of grep
and don't like ascii escape code.
这篇关于管道grep来后的grep preserve着色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!