-2

So I'm trying to show the contents of a text file with every occurrence of a particular word that is highlighted. I don't want to use grep as that only shows the sentences with that word in. I want to use the cat command.

2 Answers2

0

I still suggest you use the grep command, and specify a big context value to print out lines "near" the matching lines, e.g:

grep -C 999999999 needle haystack
jotik
  • 17,044
  • 13
  • 58
  • 123
0

Following will print whole file, and color only the matching text

   grep --color -E "PATTERN|$" data
P....
  • 17,421
  • 2
  • 32
  • 52