Colorized grep — viewing the entire file with highlighted matches

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

    I use following command for similar purpose:

    grep -C 100 searchtext file

    This will say grep to print 100 * 2 lines of context, before & after of the highlighted search text.

    0 讨论(0)
  • 2020-11-28 00:53

    I added this to my .bash_aliases:

    highlight() {
      grep --color -E "$1|\$"
    }
    
    0 讨论(0)
  • 2020-11-28 00:54

    Ok, this is one way,

    wc -l filename
    

    will give you the line count -- say NN, then you can do

    grep -C NN --color=always filename
    
    0 讨论(0)
提交回复
热议问题