I have a testResultOuput.txt
which contains lines that look like this:
[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.
and so far I find these lines with: & grep Result={Failed} testResultOuput.txt
anyone can help?
I want to write a shell script to search by Result and print only the Name={}
and Result={}
from these lines
CodePudding user response:
You may try --only-matching
grep option, which will output only matched part :
-o, --only-matching
Print only the matched (non-empty) parts of a matching line,
with each such part on a separate output line.
For example:
grep --only-matching 'Result={[[:alpha:]]*} Name={[[:alpha:]]*}'
will output with your example:
$ grep --only-matching 'Result={[[:alpha:]]*} Name={[[:alpha:]]*}' foo
Result={Failed} Name={MyAwesomeTest}
$
CodePudding user response:
How about this:
$ grep -o '\<Result={[^}]*} Name={[^}]*}' testResultOutput.txt
Result={Failed} Name={MyAwesomeTest}