以下是我的输入和输出.txt
文件。
我希望按StatusDate
和Method
对数据进行分组。
然后根据StatusDate
和Method
汇总值。
INPUT.TXT
No,Date,MethodStatus,Key,StatusDate,Hit,CallType,Method,LastMethodType
112,12/15/16,Suceess,Geo,12/15/16,1,Static,GET,12/15/16
113,12/18/16,Suceess,Geo,12/18/16,1,Static,GET,12/18/16
114,12/19/16,AUTHORIZED,Geo,12/19/16,1,Static,GET,12/19/16
115,12/19/16,AUTHORIZED,Geo,12/19/16,1,Static,GET,12/19/16
116,12/19/16,Suceess,Geo,12/19/16,1,Static,PUT,12/19/16
117,12/19/16,Suceess,Geo,12/19/16,1,Static,PUT,12/19/16
118,12/19/16,Waiting,Geo,12/19/16,1,Static,GET,12/19/16
119,12/19/16,AUTHORIZED,Geo,12/19/16,1,Static,GET,12/19/16
120,12/17/16,Suceess,Geo,12/17/16,1,Static,GET,12/17/16
121,12/17/16,Suceess,Geo,12/17/16,1,Static,GET,12/17/16
130,12/16/16,Suceess,Geo,12/16/16,1,Static,GET,12/16/16
Out.txt
StatusDate,12/15/16,12/16/16,12/17/16,12/17/16,12/18/16,12/19/16,12/19/16,12/19/16,12/19/16,12/19/16,12/19/16,Grand Total
GET,1,1,1,1,1,1,1,1,1,,,9
PUT,,,,,,,,,,1,1,2
Grand Total,1,1,1,1,1,1,1,1,1,1,1,11
我正在使用awk
并将数据拆分为awk -F, '{if($8=="GET") print }'
,然后计算总和值。
由于文件很大,所以会有延迟。
是否有可能一步到位?那么文件操作会减少吗?
答案 0 :(得分:0)
awk -F ',' '
/GET/{ Get[ $2]++}
/PUT}{ Put[ $2]++}
{Total[$2]++}
END {
printf( "StatusDate')
for (d in Total) printf( ",%s", d)
printf( "\nTotal GET")
for (d in Total) printf( ",%d", Get[d])
printf( " PUT")
for (d in Total) printf( ",%d", Put[d])
printf( " Grand Total")
for (d in Total) printf( ",%d", Total[d])
printf( "\n")
}
' Input.txt
答案 1 :(得分:0)
您可以使用关联数组来跟踪聚合。
var $scrollerOuter = $( '.mCustomScrollbar' );
var $dragger = $scrollerOuter.find( '.mCSB_dragger' );
var scrollHeight = $scrollerOuter.find( '.mCSB_container' ).height();
var draggerTop = $dragger.position().top;
var scrollTop = draggerTop / ($scrollerOuter.height() - $dragger.height()) * (scrollHeight - $scrollerOuter.height());
答案 2 :(得分:0)
$ awk -F, 'NR==1 {printf "%s",$8$2; t="Total"; v[t]; next}
{d[$2]; v[$8]; a[$2,$8]++; a[$2,t]++}
END {n=asorti(d,ds);
for(i=1;i<=n;i++) printf "%s", FS ds[i];
print "";
for(k in v)
{printf "%s", k;
for(i=1;i<=n;i++) printf "%s", FS a[ds[i],k];
print ""}}' file
MethodDate,12/15/16,12/16/16,12/17/16,12/18/16,12/19/16
PUT,,,,,2
GET,1,1,2,1,4
Total,1,1,2,1,6