The Problem
Using Bash, I have a variable with a string like this one:
STR="Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pharetra metus turpis, id rutrum massa auctor.
not ok 1 Chrome 89.0 - [158 ms] - Failed test 1 | Test Name 1
---
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus pharetra metus turpis, id rutrum massa auctor.
not ok 2 Chrome 89.0 - [158 ms] - Failed test 2 | Test Name 2
---
ok 1 Chrome 89.0 - [158 ms] - Passing...
---"
And I need to create an array containing only the name of those failing tests. The pattern/rules would be:
- Lines starting with the 'not ok' phrase.
- Then, Getting the text after the second dash until the end end-of-line.
What I have tried
So far, I came up the following regexs:
(not ok )(.*?)(\n), that will match the first rule.(?:[^-]*\-){2}([^-]*), that will match the second rule.
What I am missing
However, I am very lost on how to combine them together to generate the final desire output (an array in bash):
[
'Failed test 1 | Test Name 1',
'Failed test 2 | Test Name 2'
]