Skip to content

Instantly share code, notes, and snippets.

@felixrabe
Created October 25, 2012 16:32
Show Gist options
  • Save felixrabe/3953864 to your computer and use it in GitHub Desktop.
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.
#!/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