Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can grep (from command line) be set up to highlight the part of the line that matches?

I'm using grep from the command line via cygwin. I'm wondering if there's any way to get it to highlight the part of each line that matches the regex. The closest thing I'm seeing is the -o option, but that only outputs the matching area, and I'd like to see the entire line.

like image 780
Herms Avatar asked Nov 28 '22 20:11

Herms


2 Answers

Take a look at the --color (or --colour) option, e.g.

grep --color POST access_log 

By default, this uses the "auto" mode which only includes the color codes when output to a terminal, but not when you pipe the output elsewhere. If you want the colors piped out to something other than stdout, then use --color=always

See the linked article for ways you can change the colour and make grep use this option by default.

like image 73
Paul Dixon Avatar answered Dec 04 '22 04:12

Paul Dixon


Try the --color switch.

like image 23
Dave Costa Avatar answered Dec 04 '22 05:12

Dave Costa