开发者

time calculation with awk

I've got a file, which looks like:

Coding       |2010-04-20 12:52|2010-04-20 14:11
Documentation|2010-04-20 22:56|2010-04-21 01:13
Coding       |2010-04-21 09:51|2010-04-21 10:58
Coding       |2010-04-21 13:11|2010-04-21 14:21

What's the best way - I'm thinking of awk - to do time calculations. As result I expect:

2010-04-20 Coding         69
2010-04-21 Documentation 13开发者_如何学Python7
2010-04-21 Coding        137 

Can this be done with awk?


Can this be done with awk?

i don't know how you get those numbers 69, 137 but you can use gawk's mktime (and others like strftime etc)

awk -F"|" '
{
  gsub(/[-:]/," ",$2)
  gsub(/[-:]/," ",$3)
  m=split($2,s2," ")
  n=split($3,s3," ")
  t1=mktime(s2[1]" "s2[2]" "s2[3]" "s2[4]" "s2[5]" 0")
  t2=mktime(s3[1]" "s3[2]" "s3[3]" "s3[4]" "s3[5]" 0")
  print t2-t1
}' file

the above does not really solve your problem but just an illustration.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜