0

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

$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    
}  

这种格式的 o/p 时间1.36501e+12

我怎样才能让这个函数以正确的格式输出?

4

0 回答 0