Reprinted from: 50989335
Restore demand scenario: Test engineers also want to check the Linux logs, but face a lump of log, in addition to dazzling really no other harvest.
Solve demand scenario: Let the keywords in log color or highlight, so that the eyes can focus.
There are currently 2 types of highlights in Linux commands that are known to be useful:
1. tail-f log file |perl-pe ' s/(highlighted keywords)/\e[1;31m$1\e[0m/g '
2. tail-f log file |grep-e "highlighted keywords 1| highlighted keywords 2|...| Highlighted keyword n "-a10-b10--color=auto
Command 1 Description: This method in the "Linux Shell script Raiders" has mentioned how to change the terminal output color of the introduction, you can also refer to the Web "http://hittyt.iteye.com/blog/1927026" in the filter keyword highlighting the content. the parentheses cannot be omitted!!!
Command 2 Description: This is my friend and I Zhangshanhui in the use of Linux command to find a command, very simple is also very practical, more than the first command easier to remember, first on a picture. color Front two horizontal lines!!!
Egrep = Grep-e is an extended grep command;
-a10-b10 said that there are keywords in the upper and lower 10 line range to filter the operation of keywords, English explanation:
*context Control:
-b,–before-context=num print NUM lines of leading context
-a,–after-context=num print NUM lines of trailing context*
Try-a1-b1 Get the result and the original command is basically consistent
Try to get rid of the-a-b parameter, the result is basically consistent with the original command
–color=auto to use the keyword part of the color display, as to how to customize the color of keywords, this ... It's more complicated, please refer to the article "Add color http://blog.csdn.net/diy534/article/details/7025640 to grep commands under Linux"
Summary: Command 2 has egrep–color This command is enough to highlight the key words in the log, especially in the case of tail command this real-time refresh log record, red highlighting it, enough eye-catching, don't toss, not to mention this command and so convenient memory.
Keyword highlighting in logs in Linux