grep: highlighting matches in color

来源:互联网 发布:多普达 知乎 编辑:程序博客网 时间:2024/06/06 01:47

Many Debian users use grep regularly. But did you know that grep can highlight the text it matches in color?

Much like lsgrep supports the use of color in its output, controlled by a --color option. By default, grep outputs matching lines, but does not indicate what portion of the line matched. With --color=autogrep will highlight the matching portion of the line in color when it outputs to a terminal, while avoiding the use of any potentially-harmful terminal control sequences when standard output goes somewhere else (like a file or pipe). If you like the colorful grep, you can simply export GREP_OPTIONS='--color=auto' in your shell startup script.

grep's default highlight uses a red color. You can change this color by setting the GREP_COLOR environment variable to a different escape sequence fragment. I use export GREP_COLOR='1;32', which produces a bright green.



https://debian-administration.org/article/460/grep_highlighting_matches_in_color

原创粉丝点击