首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何删除重复行并聚合相应的值

如何删除重复行并聚合相应的值
EN

Stack Overflow用户
提问于 2017-02-03 20:02:20
回答 1查看 54关注 0票数 1

我有一个带有逗号分隔值的CSV,因为我使用JMeter的CMDRunner.jar进行性能测试,提供一段时间内的延迟/请求。

代码语言:javascript
复制
2017/02/03 11:15:41.593,15,End-to-end request-response,15
2017/02/03 11:15:41.609,6,Request body is proxied successfully to the backend,6
2017/02/03 11:15:41.616,5,x-junction-path validator,5
2017/02/03 11:15:41.622,9,Invalid content type sent by client ,9
2017/02/03 11:15:41.634,3,Invalid content type requested by client ,3
2017/02/03 11:15:42.595,10,End-to-end request-response,10
2017/02/03 11:15:42.606,10,Request body is proxied successfully to the backend,10
2017/02/03 11:15:42.616,9,x-junction-path validator,9
2017/02/03 11:15:42.625,8,Invalid content type sent by client ,8
2017/02/03 11:15:42.635,5,Invalid content type requested by client ,4
2017/02/03 11:15:43.599,3,End-to-end request-response,3
2017/02/03 11:15:43.603,6,Request body is proxied successfully to the backend,6
2017/02/03 11:15:43.609,7,x-junction-path validator,7
2017/02/03 11:15:43.617,4,Invalid content type sent by client ,4
2017/02/03 11:15:43.622,7,Invalid content type requested by client ,7

我想汇总每个请求的延迟,这意味着每个请求只有一个条目,以及相应的聚合延迟。第3列和第4列。有没有一个jmeter插件来获得这个结果,或者我如何在BASH中做到这一点?

预期输出(例如):

注意:由于这是一个聚合,所以时间戳和经过时间(第2列)是不相关的。

代码语言:javascript
复制
End-to-end request-response,12.31
equest body is proxied successfully to the backend,6.1
x-junction-path validator,5.0
Invalid content type sent by client, 3.12
Invalid content type requested by client ,3.01
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2017-02-03 20:24:26

Awk可以帮助你做到这一点,

代码语言:javascript
复制
awk 'BEGIN{FS=OFS=","}{unique[$3]+=$4; count[$3]++;}END{for (i in unique) print i, unique[i]/count[i]}' file
x-junction-path validator,7
Invalid content type requested by client ,4.66667
Invalid content type sent by client ,7
Request body is proxied successfully to the backend,7.33333
End-to-end request-response,9.33333

也可以使用浮点算术上具有.2度精度的printf,如

代码语言:javascript
复制
awk 'BEGIN{FS=","}{unique[$3]+=$4; count[$3]++;}END{for (i in unique) printf "%s,%0.2f\n", i, unique[i]/count[i]}' file
x-junction-path validator,7.00
Invalid content type requested by client ,4.67
Invalid content type sent by client ,7.00
Request body is proxied successfully to the backend,7.33
End-to-end request-response,9.33
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/42023859

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档