Color regex matches - without dropping misses

后端 未结 7 888
日久生厌
日久生厌 2021-02-07 02:21

When using grep --color=always I can get pretty color highlighting for regex matches.

However, grep only returns lines with at least one match.

相关标签:
7条回答
  • 2021-02-07 02:56

    The way you're doing this now is probably about as clean as you can expect to make this, unless of course you write your own grep tool. If you don't necessarily care about preserving the order of the output, here's the other way I can think of to do this:

    function colormatch ()
    {
        tee - | grep --color=always $1 | sort | uniq
    }
    

    Not as efficient as using sed (more processes created, and tee-ing the output), so I'd probably recommend sticking with your sed solution.

    0 讨论(0)
提交回复
热议问题