I have a large file that consists of tests run sequentially. Each test has a test name and test data. I want filter out all tests that failed into a separate file. 
- The test names are enclosed in square brackets.
- The test data in the example below are the 4 lines in each test
- If a test fails it will have the keyword FAILED in it. 
Here is a simple example:

```
[CPU]
aaaa
bbbb
cccc
[Drives]
dddd
FAILED eeee
ffff
[Memory]
gggg
hhhh
iiii
[Power]
FAILED jjjj
FAILED kkkk
llll
[Graphics]
mmmm
nnnn
oooo

```

In this example 2 of the 5 tests failed so the output file would be:

```
[Drives]
dddd
FAILED eeee
ffff
[Power]
FAILED jjjj
FAILED kkkk
llll

```

Using BASH I can use grep to find the failed lines but I don't know how I can extract the full tests including the test names. I was thinking that after finding a match with grep I would use a do while loop and output each line to the file until it finds the [] above and below it.