Another possible solution is to provide two patterns to grep
: one will be the actual pattern or term to be searched for, and the second one will be an empty string.
$ grep --color -e 'cat' -e '' testfile.txt
cat-1.15
cat-1.15
cat-1.15
cat-1.18
The -e
option is used for specify multiple patterns. From the manual:
-e PATTERN
,--regexp=PATTERN
Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern beginning with a hyphen (-). (
-e
is specified by POSIX.)
You can also combine those patterns as a single extended regular expression, if required:
$ grep --color -E 'cat|' testfile.txt
cat-1.15
cat-1.15
cat-1.15
cat-1.18
Also, you can simply add another pattern to the list if you need to highlight more than one keyword.