Colorize tail output

后端 未结 6 558
慢半拍i
慢半拍i 2021-01-30 07:27

I\'ve been trying to make tail a little more readable for server startups. My current command filters out most of the INFO and DEBUG messages from the startup:

         


        
6条回答
  •  被撕碎了的回忆
    2021-01-30 08:02

    yes, there is way to do this. That is, as long as your terminal supports ANSI escape sequences. This is most terminals that exist.

    I think I don't need explain how to grep, sed etc. point is the color right?

    see below, this will make

    WARN yellow
    ERROR red
    foo   green
    

    here is example:

    kent$ echo "WARN
    ERROR
    foo"|sed 's#WARN#\x1b[33m&#; s#ERROR#\x1b[31m&#; s#foo#\x1b[32m&#'
    

    Note: \x1b is hexadecimal for the ESC character (^VEsc).

    to see the result:

    enter image description here

提交回复
热议问题