Skip to main content
We’ve updated our Terms of Service. A new AI Addendum clarifies how Stack Overflow utilizes AI interactions.
2 of 4
replaced http://serverfault.com/ with https://serverfault.com/

The accepted answer https://serverfault.com/a/310104 can be a bit slow, if a lot of lines have to be processed, with the overhead of starting the date process allowing about 50 lines per second in Ubuntu, and only about 10-20 in Cygwin.

When bash can be assumed a faster alternative would be the printf builtin with its %(...)T format specifier. Compare

>> while true; do date; done | uniq -c 47 Wed Nov 9 23:17:18 STD 2016 56 Wed Nov 9 23:17:19 STD 2016 55 Wed Nov 9 23:17:20 STD 2016 51 Wed Nov 9 23:17:21 STD 2016 50 Wed Nov 9 23:17:22 STD 2016 >> while true; do printf '%(%F %T)T\n'; done | uniq -c 20300 2016-11-09 23:17:56 31767 2016-11-09 23:17:57 32109 2016-11-09 23:17:58 31036 2016-11-09 23:17:59 30714 2016-11-09 23:18:00 
kdb
  • 200
  • 1
  • 5