彩色 grep — 查看帶有突出顯示匹配項的整個文件 - Colorized grep — viewing the entire file with highlighted matches

問題:

I find grep 's --color=always flag to be tremendously useful.我發現grep--color=always標誌非常有用。 However, grep only prints lines with matches (unless you ask for context lines).但是,grep 只打印帶有匹配項的行(除非您要求提供上下文行)。 Given that each line it prints has a match, the highlighting doesn't add as much capability as it could.鑑於它打印的每一行都有一個匹配項,突出顯示並沒有儘可能多地增加功能。

I'd really like to cat a file and see the entire file with the pattern matches highlighted.我真的很想cat一個文件並查看整個文件,其中突出顯示了模式匹配。

Is there some way I can tell grep to print every line being read regardless of whether there's a match?有什麼方法可以告訴 grep 打印正在讀取的每一行,而不管是否匹配? I know I could write a script to run grep on every line of a file, but I was curious whether this was possible with standard grep .我知道我可以編寫一個腳本來在文件的每一行上運行 grep,但我很好奇這是否可以使用標準grep


解決方案:

參考一: https://stackoom.com/question/47MH
參考二: Colorized grep — viewing the entire file with highlighted matches
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章