Colour highlighting output based on regex in shell

后端 未结 8 1937
鱼传尺愫
鱼传尺愫 2020-12-02 07:32

I\'d like to know if I can colour highlight the output of a shell command that matches certain strings.

For example, if I run myCommand, with the output below:

8条回答
  •  孤街浪徒
    2020-12-02 08:26

    There is an answer in superuser.com:

    your-command | grep -E --color 'pattern|$'
    

    or

    your-command | grep --color 'pattern\|$'
    

    This will "match your pattern or the end-of-line on each line. Only the pattern is highlighted..."

提交回复
热议问题