我有一個testResultOuput.txt包含如下所示的行:
[2022.03.03-13.28.59:742][394]LogAutomationController: Error: Test Completed. **Result={Failed}** **Name={MyAwesomeTest}** Path={AutoTests.UnitTests}
[2022.03.03-13.28.59:742][394]LogAutomationController: BeginEvents: AutoTests.UnitTests
[2022.03.03-13.28.59:742][394]LogAutomationController: Error: Expected 'MyAwesomeTest' to be 0.000000, but it was -2147483648.000000 within tolerance 0.000100.
到目前為止,我發現這些行:& grep Result={Failed} testResultOuput.txt
有人可以幫忙嗎?
我想撰寫一個 shell 腳本來按 Result 搜索并只列印這些行中的Name={}andResult={}
uj5u.com熱心網友回復:
您可以嘗試--only-matchinggrep 選項,它只會輸出匹配的部分:
-o, --only-matching
Print only the matched (non-empty) parts of a matching line,
with each such part on a separate output line.
例如:
grep --only-matching 'Result={[[:alpha:]]*} Name={[[:alpha:]]*}'
將與您的示例一起輸出:
$ grep --only-matching 'Result={[[:alpha:]]*} Name={[[:alpha:]]*}' foo
Result={Failed} Name={MyAwesomeTest}
$
uj5u.com熱心網友回復:
這個怎么樣:
$ grep -o '\<Result={[^}]*} Name={[^}]*}' testResultOutput.txt
Result={Failed} Name={MyAwesomeTest}
轉載請註明出處,本文鏈接:https://www.uj5u.com/ruanti/436705.html
