I have a situation similar to [Bash, grep between two lines with specified string](https://stackoverflow.com/questions/22221277/bash-grep-between-two-lines-with-specified-string). I have a text file with output in the following format:

```
HEADER A
lines of output
----------------
HEADER B
lines of output
----------------
...rinse and repeat...

```

I want to match all the blocks with the same header. `grep` does not seem sufficient for this task. And I am only vaguely familiar with `awk` and `sed`. Just enough to realize they might be the most appropriate tools here. So how do I match a block that is enclosed with matching HEADER and ---------- lines?

My attempt based on the linked question is

```
awk '/HEADER/{f=1} /-/{f=0;print} f' filename.txt

```

However, this still matches some of the lines in the blocks with the second header.