Skip to content

Instantly share code, notes, and snippets.

@DavidEGx
Created February 24, 2013 16:56
Show Gist options
  • Save DavidEGx/5024547 to your computer and use it in GitHub Desktop.
Save DavidEGx/5024547 to your computer and use it in GitHub Desktop.
Example of tailing a log file with some colors using grep
#!/bin/bash
# Tail an apache log an put some colors into the output
# www.davideg.es
shopt -s expand_aliases
alias grey-grep="GREP_COLOR='1;30' grep -E --color=always --line-buffered"
alias red-grep="GREP_COLOR='1;31' grep -E --color=always --line-buffered"
alias green-grep="GREP_COLOR='1;32' grep -E --color=always --line-buffered"
alias yellow-grep="GREP_COLOR='1;33' grep -E --color=always --line-buffered"
alias cyan-grep="GREP_COLOR='1;36' grep -E --color=always --line-buffered"
tail -1000f /var/log/apache2/error.log | grey-grep ".*PerformanceLogger.*|$" | cyan-grep "INFO|$" | yellow-grep "WARN|$" | red-grep "[ERROR].*|[FATAL].*|$" | green-grep "***|$"
@kevindaus
Copy link

can you site more example sir?

@ctubio
Copy link

ctubio commented Feb 7, 2017

@kevindaus heres most basic example, use as you wish:
tail -f file.log | egrep pattern --line-buffered --color

@aitounejjar
Copy link

This is awesome. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment