Preserve colouring after piping grep to grep

后端 未结 4 1241
遇见更好的自我
遇见更好的自我 2021-01-30 05:07

There is a simlar question in Preserve ls colouring after grep’ing but it annoys me that if you pipe colored grep output into another grep that the coloring is not preserved.

4条回答
  •  逝去的感伤
    2021-01-30 05:18

    A word of advice:

    When using grep --color=always, the actual strings being passed on to the next pipe will be changed. This can lead to the following situation:

    $ grep --color=always -e '1' * | grep -ve '12'
    11
    12
    13
    

    Even though the option -ve '12' should exclude the middle line, it will not because there are color characters between 1 and 2.

提交回复
热议问题