我不太熟悉grep或类似命令的一些更高级的方面,但这正是我所要做的。
我有一个应用程序日志,我对其进行了改进,并将结果写入了一个文件。(对特定错误表示欢迎)。
现在,我想通过productId实现这个新文件(每个错误消息都有一个productId,但错误消息的其他内容有所不同),并将productIds与#组合在一起,#指示产品id在日志中出现的次数。
示例日志:
[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,计数)
1AHREA4315 134
ATAC15414319 2341
431AREAB341 3等。
不一定要漂亮,我只是想获得productId引起问题的原因以及哪些问题比其他问题更多的数据。
发布于 2016-11-12 03:04:22
假设产品ID上没有空白,以下内容将适用于许多Bash版本:
#!/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/结果文件中。
https://stackoverflow.com/questions/40558611
复制相似问题