Skip to main content
Commonmark migration
Source Link

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.

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.

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.

Minor formatting edit.
Source Link
Haxiel
  • 8.7k
  • 1
  • 23
  • 32

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 PATTERN, --regexp=regexp=PATTERNPATTERN 

Use PATTERN as the pattern. This can be used to specify multiple search patterns, or to protect a pattern 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.

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.

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.

Source Link
Haxiel
  • 8.7k
  • 1
  • 23
  • 32

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.