Colorized grep — viewing the entire file with highlighted matches

前端 未结 21 2483
野趣味
野趣味 2020-11-28 00:17

I find grep\'s --color=always flag to be tremendously useful. However, grep only prints lines with matches (unless you ask for context lines). Give

21条回答
  •  悲&欢浪女
    2020-11-28 00:46

    It might seem like a dirty hack.

    grep "^\|highlight1\|highlight2\|highlight3" filename
    

    Which means - match the beginning of the line(^) or highlight1 or highlight2 or highlight3. As a result, you will get highlighted all highlight* pattern matches, even in the same line.

提交回复
热议问题