Skip to content

Instantly share code, notes, and snippets.

@reinhrst
Created March 27, 2012 00:29
Show Gist options
  • Save reinhrst/2210980 to your computer and use it in GitHub Desktop.
Save reinhrst/2210980 to your computer and use it in GitHub Desktop.
Each line of output is preceded by a timestamp. The timestamp is printed as soon as the first character on the newline is produced
#!/bin/bash
WASNL=1;
NL="$(/bin/echo)";
while [[ true ]]; do
IFS= read -r -n 1 C;
if [ $WASNL -eq 1 ]; then
/bin/echo -n $(date "+%Y-%m-%d %H:%M:%S") "";
fi;
if [[ "$C" == "$NL" ]]; then
WASNL=1;
/bin/echo "";
else
WASNL=0;
/bin/echo -n "$C";
fi;
done
@reinhrst
Copy link
Author

Still some problems: output is rather slow, and if input pipe breaks strange things happen. Definitely alpha version

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment