Multicolored Grep
Last Updated by Code Sport. Filed under linuxGREP_COLORS and How to Change the Color of Grep Output Note: You…
Note: You may use either double or single quotes. Choose your favorite and stick with it for consistency. We decided to use double and single in these examples for illustrative purposes.
Scenario 1 – Access Logs: Which IPs accessed my WordPress plugins directory on Sep 15, 2015? Color the date and time in the default color (red) and the plugin accessed in light blue (1;34):
grep '15/Sep/2015.*]' --color=always /path_to/log_file/log/access.log | GREP_COLORS='mt=1;34' grep 'plugins/.*HTTP/' --color=always |more
Scenario 2 – Error Logs: Find which IPs are generating errors on my server from Sep 20 to Sep 29, 2015. Also, highlight the IPs in white (1;37) and the event date in the default color:
grep "Sep 2.*2015" --color=always /path_to/log_file/error.log | GREP_COLORS="mt=1;37" grep "client .*]" --color=always |more
Where:
Image from Ben Arwin: