Colorized grep — viewing the entire file with highlighted matches

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

    You can also create an alias. Add this function in your .bashrc (or .bash_profile on osx)

    function grepe {
        grep --color -E "$1|$" $2
    }
    

    You can now use the alias like this: "ifconfig | grepe inet" or "grepe css index.html".

    (PS: don't forget to source ~/.bashrc to reload bashrc on current session)

提交回复
热议问题