Colorized grep — viewing the entire file with highlighted matches

前端 未结 21 2436
野趣味
野趣味 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:44

    I'd like to recommend ack -- better than grep, a power search tool for programmers.

    $ ack --color --passthru --pager="${PAGER:-less -R}" pattern files
    
    $ ack --color --passthru pattern files | less -R
    
    $ export ACK_PAGER_COLOR="${PAGER:-less -R}"
    $ ack --passthru pattern files
    

    I love it because it defaults to recursive searching of directories (and does so much smarter than grep -r), supports full Perl regular expressions (rather than the POSIXish regex(3)), and has a much nicer context display when searching many files.

提交回复
热议问题