Created
October 25, 2012 16:32
-
-
Save felixrabe/3953864 to your computer and use it in GitHub Desktop.
Timestamped grep-ing for log files and similar sources that provide no timestamps.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Public domain. Written by Felix Rabe in 2012. | |
# Timestamped grep-ing for log files and similar sources that provide no timestamps. | |
# Usage example (used for a Redmine 1.4 / Rails 2.3 project): | |
# tail -f log/production.log | timedgrep email | |
look_for="$1" | |
while read ln ; do | |
# Tried this first, didn't work: grep ... | while ... do ... done | |
( echo "$ln" | grep -q "$look_for" ) && | |
echo "$(date '+%H:%M:%S') $ln" | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment