- 论坛徽章:
- 15
|
本帖最后由 rdcwayx 于 2014-04-22 15:30 编辑
缺省认为你的文件是日志文件,本身已经按照时间排序了。 这个awk命令可以列出30分钟内(00-29,30-59),每个IP的最大和最小时间戳。
留个homework,你自己计算时间戳差值吧。- awk '{split($2,a,":");a[2]=int(a[2]/30);str=$1 FS a[1] FS a[2] FS $3;if (!b[str]++) {start[str]=$1 FS $2};end[str]=$1 FS $2}END{for (i in b) print i, start[i],end[i]}' OFS="|" file
- 2014-04-18 00 0 123.125.71.19|2014-04-18 00:00:08|2014-04-18 00:00:16
- 2014-04-18 00 0 123.125.71.47|2014-04-18 00:00:29|2014-04-18 00:00:29
- 2014-04-18 00 0 220.181.108.141|2014-04-18 00:00:21|2014-04-18 00:00:22
- 2014-04-18 00 1 123.125.71.19|2014-04-18 00:30:16|2014-04-18 00:59:16
- 2014-04-18 00 0 220.181.108.180|2014-04-18 00:00:22|2014-04-18 00:00:22
- 2014-04-18 00 0 220.181.108.153|2014-04-18 00:00:21|2014-04-18 00:00:22
- 2014-04-18 00 0 123.125.71.40|2014-04-18 00:00:16|2014-04-18 00:00:16
复制代码 |
|