ripgrep
Use ripgrep with its --passthru parameter:
rg --passthru pattern file.txt It's one of the fastest grepping tools, since it's built on top of Rust's regex engine which uses finite automata, SIMD and aggressive literal optimizations to make searching very fast.
--passthru- Print both matching and non-matching lines.
Another way to achieve a similar effect is by modifying your pattern to match the empty string. For example, if you are searching using
rg foothen usingrg "^|foo"instead will emit every line in every file searched, but only occurrences of foo will be highlighted. This flag enables the same behavior without needing to modify the pattern.