码迷,mamicode.com
首页 > 系统相关 > 详细

shell 统计GMT0 时区的数据

时间:2016-05-24 13:25:56      阅读:291      评论:0      收藏:0      [点我收藏+]

标签:

和某个供应商核对数据,对方是GMT+0时区,我方报表默认北京时间,无法修改为GMT0,

对excel中按照小时级别的数据导出到excel处理,然后转为文本文件,shell转为GMT0进行统计:

前期处理:

先将时间转为"2016-05-01 00:08:00" 格式的数据,便于时间戳的比较。

去除无效的","和"$"符号,便于shell文本处理。

先解决一天的问题,然后循环调用脚本 解决多天的问题。

# for i in `seq  20160501 20160518`  ; do    sh tongji.sh "$i"; done
#!/bin/bash
#test.sh
zone=8
day=20160518
if [  $1 !=  " "  ]  ; then  
day=$1
fi

time_begin=`date -d "+$zone hour $day" +"%Y-%m-%d %H:%M:%S"`
time_end=`date -d "+$zone hour +1 day $day" +"%Y-%m-%d %H:%M:%S"`
echo "time_begin is:  $time_begin , time_end is $time_end"
filename="may-1-18-cost-imp.txt"
cat  "$filename"  |awk -F "\t"   {  
     if ($3>= ""$time_end"" || $3 < ""$time_begin"") {         
        next;
    }else {
          print $3 ,$15
    }
    if( $15 != "-" ){
        cost += $15
    }
    
    if( $7 != "-" ){
        impress += $7
    }
    

}END{
print    impress, cost

}

 

shell 统计GMT0 时区的数据

标签:

原文地址:http://www.cnblogs.com/lavin/p/5522984.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!