shell - 直接从 shell 搜索关键字并获取计数,而无需将日志保存到外部文件中
问题描述
我正在执行我的 jar 文件,它将在 shell 中创建日志。我的要求是直接从 shell 中搜索关键字,而不创建日志文件。使用此代码执行
`E:\Innoviti\BankInterfaceAumation>java -jar BankInterfaceAumation.jar 1`
Here is the logs
这是我执行 jar 时创建的日志
` 3:000000:000000 PASSED4:null:000000001600 FAILED
39:00:00 PASSED------------------------Response Conditions Passed----------------------------
AFter Sale terminal is null
2018-09-06 13:23:23 INFO UniPayTerminalDataFetcherImpl:33 - Fetching unipay terminal with id
Cached terminal or after sale terminal is null/could not be fetched cached terminal is nullAfter sale txn bank terminal null
base transaction is null/could not be fetched
Executing unipay terminal assertions ********************************************
Test Scenario total_txn_amt null SAME null Passed
Comapring property key_exchanged_on value expression SAME
Comparing Simple Exrepssion property SAME
Test Scenario key_exchanged_on null SAME null Passed
Comapring property utid_state value expression 00
Test Scenario utid_state null 00 Failed
Comapring property key_exchanged value expression SAME
L00005022018090613231871319216803136 失败`
关键字 =Failed
解决方案
您可以将日志“管道”到:
grep -o 'Failed' | wc -l
这将计算“失败”的出现次数。如果您需要搜索不区分大小写的命令,则该grep
命令变为grep -io
您的命令将变为:
E:\Innoviti\BankInterfaceAumation>java -jar BankInterfaceAumation.jar 1 | grep -o 'Failed' | wc -l
如果您想要一个执行示例,您可以尝试:
echo -e 'first line\nfailed Failed\nanother line with failed\nlast line' | grep -io 'failed' | wc -l
该命令的解释可以在这里找到:https ://explainshell.com/explain?cmd=echo+-e+%27Some+Failed+text%27+%7C+grep+-o+%27Failed%27+%7C+wc+- l
推荐阅读
- c# - Unity tansform.forward 我如何使用它来左右移动或者是否有 transfrom.left?
- javascript - 在 keyup 的输入框中查找 http:// 或 https:// 并将其删除的脚本
- opencv - Opencv(JS)从图像中选择手指区域
- api - 在 Windows 服务中自托管 ASPNET 核心 5.0 Web API 的问题
- sql-server - SQL 连接查询与“on”异常
- next.js - 从 next.js 项目上传源地图到哨兵的推荐方法是什么
- c++11 - 字符串化宏中的参数
- python - 我想将我的 Minecraft 控制台数据发送到我的应用程序中
- powershell - 在我的函数中使用 Switch 的问题
- amazon-web-services - 将秒数格式化为 Redshift 中的间隔 HH:MM:SS