Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
bash function for adding timestamps
#!/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