Here’s a neat little trick I learned today I thought was worth sharing. Sometimes I want to highlight text in a terminal screen using grep but without filtering other lines out. Here’s how you do it…

mysqlbinlog mysql-bin.000473 | grep --color -E '^|not closed';

The important part is the regexp in grep. The first section matches any line, but doesn’t colour it, the section after the pipe is the text you want to highlight. Output will look something like below.

binlog_not_closed_properly