Created
March 27, 2012 00:29
-
-
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
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 | |
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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Still some problems: output is rather slow, and if input pipe breaks strange things happen. Definitely alpha version