How to modify the cat command to highlight a chosen word?

Hi,

I'm fairly new to programming and was just wondering... Is it possible to modify the cat command (using a linux virtual machine) so that it displays text of a file and highlights a specifically chosen word? I've been looking for how to do it on the internet and can't find any helpful suggestions...

Thanks. :slight_smile:

I'm afraid, no. cat does exactly this:

You CAN make it show some special chars, too, but that's it.

BTW, "highlighting" is quite fuzzy an action. What is "highlight"? Print in bold? in red? underlined? Do it when outputting to screen? Printing? Sending it with mail, or putting it in an HTML file? All those MAY have different mechanisms to highlight.

You could do some text modifications with e.g. sed , e.g. when outputting to a VT102 (ECMA-48) compatible terminal:

sed "s/AM0./$BOLD&$OFF/" file
000000000001AM00 1500895700000000000199
000000000001AM01 035000000000013000399820810000000P

Despite RudiC has already come up with some rather elaborate workarounds: the short answer is you can't. The reason is (as RudiC also mentioned) that cat is intended for a different purpose.

Your questions amounts to "can i modify a hammer so that it drills holes". Yes, maybe, somehow, but why not use a drilling machine instead, which will be better suited for that from the start?

You can use sed as mentioned to decorate certain words or phrases with highlighting code, but that is quirky at best and certainly not very portable (chances are it won't work in the same way on another system). If you just want to search for something and want to have it easier to see the found pieces use the grep facility. In your Linuy system the grep has a --color option which should do what you want. If memory serves right this is even on by default. Otherwise cosult the man page of it.

I hope this helps.

bakunin

If your system has support for it, using `it' as an example:

grep --color=auto -E 'it|' indigofox.txt
I'm fairly new to programming and was just wondering...
Is it possible to modify the cat command (using a linux virtual machine)
so that it displays text of a file and highlights a specifically chosen word?
I've been looking for how to do it on the internet and
can't find any helpful suggestions...