The following chain of commands are to
ping with datestamp (UNIX),
convert the UNIX datestamp to more human-readable format, and
output to the terminal and a log file.
ping -D localhost 2>&1 | sed 's/^\[\([0-9]*\.[0-9]*\)\]\(.*$\)/echo "[`date -d @\1 +"%Y-%m-%d %H:%M:%S"`] \2"/e' | tee -a ping.log
Problem is that as written, the output seems to be buffered in chunks of almost a minute or ~50 lines, unlike the usual second-by-second and line-by-line output from ping.
What is causing the buffering and how can it be avoided?
ping
immediately in pipeline. If you have GNU sed you can try adding the-u
or--unbuffered
option – steeldriver Sep 11 '18 at 01:03-u
flag tosed
avoids the buffering. – adatum Sep 11 '18 at 01:07sed
instead ofgrep
. The specific C program being invoked makes little difference. – JdeBP Sep 11 '18 at 08:57