Skip to content

Instantly share code, notes, and snippets.

@Pyrolistical
Created November 28, 2014 00:59
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 Pyrolistical/5dd89275336c032af31b to your computer and use it in GitHub Desktop.
Save Pyrolistical/5dd89275336c032af31b to your computer and use it in GitHub Desktop.
timestamp each line from stdin
#!/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