$ awk '{ print strftime("%Y-%m-%d %H:%M:%S"), $0; }' /dev/ttyUSB0
$ awk '{ print strftime("%H:%M:%S"), $0; }' /dev/ttyUSB0
$ awk '{ cmd = "date +\"%a, %b %d %Y %T.%6N\""; cmd | getline dt; close(cmd); print dt, $0; fflush(); }' /dev/ttyACM0
save to file
$ stdbuf -oL awk '{ print strftime("%H:%M:%S"), $0; }' /dev/ttyUSB0 > file_name
or
$ stdbuf -oL awk '{ print strftime("%H:%M:%S"), $0; }' /dev/ttyUSB0 | tee file_name
ref :
Add timestamp to cat output from shell script
沒有留言:
張貼留言