-
-
Save Pyrolistical/5dd89275336c032af31b to your computer and use it in GitHub Desktop.
timestamp each line from stdin
This file contains 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 | |
DATECMD='gdate +%s%N' | |
process_stdout() { | |
while read line; do | |
echo -e `$DATECMD`"\t$line" | |
done | |
} | |
process_stderr() { | |
while read line; do | |
echo -e `$DATECMD` 1>&2 | |
done | |
} | |
if (( $# == 0 )); then | |
process_stdout | |
else | |
exec 3>&1 | |
( bash -c "$*" | process_stdout ) 2>&1 1>&3 | process_stderr | |
exec 3>&- | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment