首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >productIds的Grep日志和productId的组结果?

productIds的Grep日志和productId的组结果?
EN

Stack Overflow用户
提问于 2016-11-12 01:23:28
回答 1查看 95关注 0票数 0

我不太熟悉grep或类似命令的一些更高级的方面,但这正是我所要做的。

我有一个应用程序日志,我对其进行了改进,并将结果写入了一个文件。(对特定错误表示欢迎)。

现在,我想通过productId实现这个新文件(每个错误消息都有一个productId,但错误消息的其他内容有所不同),并将productIds与#组合在一起,#指示产品id在日志中出现的次数。

示例日志:

代码语言:javascript
复制
[ERROR] Some class, error info..., for request 13143, with productId=1AHREA4315, location=4314131, timestamp=1431314143141
[ERROR] other class, other error..., for request 13145, with productId=ATAC15414319, location=431531, timestamp=14314314151
... (thousands of errors, many for the same productId)

期望输出的示例:(productId,计数)

代码语言:javascript
复制
1AHREA4315 134 
ATAC15414319 2341
431AREAB341 3

等。

不一定要漂亮,我只是想获得productId引起问题的原因以及哪些问题比其他问题更多的数据。

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-11-12 03:04:22

假设产品ID上没有空白,以下内容将适用于许多Bash版本:

代码语言:javascript
复制
#!/bin/bash

#Assuming that Product IDs do not have a blank space
grep -o -P 'productId=.*? ' /folder/file > /tmp/pid-holder

#cleaning up everything but the product id value
sed 's/^..........//' /tmp/pid-holder > /tmp/pid-holder2 && sed 's/..$//' /tmp/pid-holder2 > /tmp/pid-holder3

#counting and storing result on a file
sort /tmp/pid-holder3 | uniq -c > /tmp/result

exit 0

结果将存储在/tmp/结果文件中。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/40558611

复制
相关文章

相似问题

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