| raw e-mail | index | archive | help
which ts=20 3=2E Using perl (no external dependency) your_command | perl -pe 'chomp($t=3D`date "+[%Y-%m-%d %H:%M:%S]"`); print = "$t ";'=20 4=2E Using sed and shell substitution (less precise, per run not per line) If you only need a timestamp at command start, not per line: your_command | sed "s/^/[$(date '+%Y-%m-%d %H:%M:%S')] /"=20 That inserts the same timestamp on every line (not updating between lines)= =2E =E2=9C=85 Recommended for FreeBSD scripts If ts is available =E2=86=92 use it=2E If not, prefer the awk version (portable, no extra dependencies)=2E Would you like the timestamp to include milliseconds too? I can adapt the = command for that (FreeBSD date supports %N for nanoseconds)=2E
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?>