shell 统计GMT0 时区的数据

和某个供应商核对数据,对方是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

}'

 

posted on 2016-05-24 12:14  iokde.com  阅读(1192)  评论(0编辑  收藏  举报

导航