tail -f

linux view log, highlight keywords

As a back-end development, it is inevitable that you need to check the log. Sometimes you need to highlight some keywords in the log to quickly determine the location of the log; the
most basic tail -f xxx.log (probably everyone will)
want to highlight it Some log fields, such as displaying Error in red, (Well, it’s actually very simple, Baidu can know the command at once, tail -1000f xxx.log | perl -pe's/(Error)/\e[1 ;31m$1\e[0m/g') It’s
Insert picture description here
very uncomfortable to enter such a long list of commands every time, even if copy and paste is not fun, (forgive me for being such a lazy ape)
So, write a script?
No bb, go directly to the script

#!/bin/bash
log=$1
str=$2
order=“tail -1000f l o g ∣ p e r l − p e ′ s / ( log | perl -pe 's/( logperlp es/(str)/\e[1;31m$str\e[0m/g’”
eval $order

Don’t ask me why I wrote it like this. I don’t know. It’s fine. As for how to use it, cd directly to your log file directory and type the command

flog xxx.log Error

Insert picture description here

flog is the name of your script, xxx.log is the name of your log file, and Error is the keyword you want to highlight (if you don’t like red, or you want other special effects, you can go to Baidu to change it. The above command will do) The
last sentence, the first time you post, don’t scold me

Guess you like

Origin blog.csdn.net/pjw1217/article/details/110437197