awk处理大数字的方式

时间:2013-06-18 19:08:09

标签: awk

当我尝试将下面的代码放在命令行选项中时它可以工作,但是当我将这个分割放在一个函数中然后我给它打印时它不起作用。

$1 is date $2 time and format is as below, here 549 is in milliseconds.      
2013-05-03 18:23:24, 549    

awk -F "[;& ]" '   
     {st[$13]=$1 " " $2}     
     {en[$13]=$1 " " $2}     
    END {    
    for (i in st) {    
        split(st[i],s,"[- :,]")    
        start=mktime(s[1] " " s[2] " " s[3] " " s[4] " " s[5] " " s[6])   

        split(en[i],e,"[- :,]")   
        end=mktime(e[1] " " e[2] " " e[3] " " e[4] " " e[5] " " e[6])    

        diff=(end*1000+e[7])-(start*1000-s[7])    
        print i,diff }    
    }' test.log 

此处输出为所需格式1960

分割功能时的代码

function calc (date, time, newtime) {  
st[i] = date " " time  
split(st[i],s,"[- :,]")    
start=mktime(s[1] " " s[2] " " s[3] " " s[4] " " s[5] " " s[6])     
newtime=start*1000+s[7]
return newtime    
}  

以这种格式1.36501e+12

的时间

如何让这个函数以正确的格式输出?

0 个答案:

没有答案