Issue
When using grep, it will highlight any text in a line with a match to your regular expression.
What if I want this behaviour, but have grep print out all lines as well? I came up empty after a quick look through the grep man page.
Solution
Use ack. Check out its --passthru
option here: ack. It has the added benefit of allowing full Perl regular expressions.
$ ack --passthru 'pattern1' file_name
$ command_here | ack --passthru 'pattern1'
You can also do it using grep like this:
$ grep --color -E '^|pattern1|pattern2' file_name
$ command_here | grep --color -E '^|pattern1|pattern2'
This will match all lines and highlight the patterns. The ^
matches every start of the line but won't get printed/highlighted since it's not a character.
(Note that most of the setups will use --color by default. You may not need that flag).
Answered By - holygeek Answer Checked By - Dawn Plyler (WPSolving Volunteer)