Skip to content

Instantly share code, notes, and snippets.

@Jared-Prime
Forked from sfgeorge/timestamp_it.sh
Created April 3, 2014 21:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jared-Prime/9963663 to your computer and use it in GitHub Desktop.
Save Jared-Prime/9963663 to your computer and use it in GitHub Desktop.
#!/bin/bash
# Adds a timestamp beside every line of data received on STDIN.
# Turns this -> Into that:
# -> Time Data
# [INFO] event 1 -> 04-03-2014 12:00:01 [INFO] event 1
# [INFO] event 2 -> 04-03-2014 12:00:02 [INFO] event 2
# example usage: tail -f some.log | timestamp_it > some-timed.log
function timestamp_it {
echo -e "Time\tData"
while read line
do
date=$(date '+ %m-%d-%Y %H:%M:%S')
echo -e "$date\t$line"
done
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment