Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is strftime with nanoseconds possible in bash?

Is there any way to obtain Unix Time with nanoseconds with strftime in bash?

My line for unix time :

<command> |  awk '{ print strftime("%s"),  $0; }'

I cannot use date +%N because date is only evaluated once.

Is there any work around?

like image 889
Martin Avatar asked Aug 05 '10 19:08

Martin


1 Answers

I found a workaround using while read. date gets updated that way. No need for strftime.

<command> |  while read line; do d=`date +%s%N`; echo $d $line; done
like image 151
Martin Avatar answered Sep 25 '22 20:09

Martin