Friday, 8 August 2014

Easy way to timestamp date on Ubuntu bash


ts from the moreutils package can be used to timestamp data:


~$ echo my_time_stamp_test | ts

Aug 08 08:09:14 my_time_stamp_test

The timestamp format can be changed as well

:~$ echo my_time_stamp_test | ts [%H.%M.%.S]

[08.12.05.066785] my_time_stamp_test

so to timestamp data collected from a serial port something like below can be used:

ts </dev/ttyS0 >arduino.log

And a true bash version :
<command> | awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; fflush(); }'

No comments:

Post a Comment