如何分析使用awk时间跟踪报告? [英] How to analyze time tracking reports with awk?

查看:150
本文介绍了如何分析使用awk时间跟踪报告?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要追踪我的时间有两个伟大的工具, todotxt 并的。随着这些中的一个
            可以生成报告看起来像这样的:

I'm tracking my time with two great tools, todotxt and punch. With these one can generate reports that look like this:

2012-11-23 (2 hours 56 minutes):
    first task (52 minutes)
    second task (2 hours 4 minutes)
2012-11-24 (2 hours 8 minutes):
    second task (2 hours 8 minutes)

我的问题:什么是分析这种输出的一个方便的方法?例如。
我怎么能总结一下就是花在第一项任务/第二个任务的时候还是发现
            我总的工作时间更长的时间,如2012-11 - *?

My question: what's a convenient way for analyzing this kind of output? E.g. how could I sum up the time that is spent doing "first task"/"second task" or find out my total working hours for a longer period such as "2012-11-*"?

所以,我想有一个命令,如 punch.sh报告/正则表达式换日期或任务 - 我 - 有兴趣入/

So, I'd like to have a command such as punch.sh report /regex-for-date-or-task-i'm-interested-in/.

<我一个href=\"http://snippets.aktagon.com/snippets/15-Log-file-analysis-with-AWK-Calculating-the-sum-and-average\"相对=nofollow>阅读和看到,这是可能的 AWK 。但我不知道如何1)总和分钟+小时,2)提供用空格任务名称作为awk的变量。

I read and saw that this is possible with awk. But I don't know how to 1) sum minutes + hours and 2) provide "task names with spaces" as variables for awk.

更新:
我还标注我的任务与 +标记来标记不同的项目(如第一项任务+ projecttag )。因此,它也将是巨大的花费总和在所有任务,特定标记的时间。

UPDATE: I'm also tagging my tasks with +tags to mark different projects (as in first task +projecttag). So it would also be great to sum the time spent on all tasks with a certain tag.

感谢您的帮助!

推荐答案

在运行此脚本之前。请取消对相应 GSUB()功能。像运行:

Before running this script. Please uncomment the appropriate gsub() function. Run like:

awk -f script.awk file

目录 script.awk

BEGIN {
    FS="[( \t)]"
}

/^\t/ {
    line = $0

#### If your input has...

##   No tags, show hrs in each task
#    gsub(/^[\t ]*| *\(.*/,"",line)

##   Tags, show hrs in each task
#    gsub(/^[\t ]*| *\+.*/,"",line)

##   Tags, show hrs in each tag
#    gsub(/^[^+]*\+| *\(.*/,"",line)

####

    for(i=1;i<=NF;i++) {
        if ($i == "hours") h[line]+=$(i-1)
        if ($i == "minutes") m[line]+=$(i-1)
    }
}

END {
    for (i in m) {
        while (m[i] >= 60) { m[i]-=60; h[i]++ }
        print i ":", (h[i] ? h[i] : "0") " hrs", m[i], "mins"
    }
}

这篇关于如何分析使用awk时间跟踪报告?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆