原帖:
处理前:
文件a:
652 10710 WQL100 9 81x11x11 2013/9/7 10:30
702 10710 WSD120 8 18x888xx 2013/9/6 12:40
808 10710 WSP229 8 11111xxx 2013/9/6 4:50
448 10711 OPH522 7 111x1x11 2013/9/4 17:10
408 10711 TEW900 9 11x1x111 2013/9/8 10:01
602 10711 TPT100 9 11111x11 2013/9/6 23:02
213 10712 WQER39 4 1xx1x1x1 2013/9/6 11:40
213 10712 WQET39 4 11xxx1x1 2013/9/6 13:40
文件b:
10710 2013/9/6 11:00
10711 2013/9/7 12:00
10712 2013/9/7 11:00
处理后:
10710 2013/9/6 11:00 2
10711 2013/9/7 12:00 0
10712 2013/9/7 11:00 *
具体要求请看原帖。
-
$ awk 'function f(x,y){split(x,a,"/");split(y,b,":");return mktime(sprintf("%d %02d %02d %02d %02d %02d",a[1],a[2],a[3],b[1],b[2],0))}function g(z){gsub(/[^x]/,0,z);gsub(/x/,1,z);return z}NR==FNR{c[$2][f($6,$7)]=f($6,$7);d[$2][f($6,$7)]=$5;next}{for(i=0;i++=f($2,$3)&&i!=1){s=g(d[$1][c[$1][i-1]])+g(d[$1][c[$1][i]]);print $0,gsub(/2/,0,s);next}print $0,"*"}' a b
-
10710 2013/9/6 11:00 2
-
10711 2013/9/7 12:00 0
-
10712 2013/9/7 11:00 *
阅读(2284) | 评论(1) | 转发(0) |