I have a file structured like that:
BOF
-------Title1-------
stuff here
some stuff
-------Title2-------
extra things
extra things
extra things
-------Title3-------
and some stuff
here
...
-------Title4-------
stuff
EOF
Now I would like to do something like this:
grep-by-section KEYWORD DELIMITER my-file
so that
grep-by-section "some" "^---" my-file
outputs
-------Title1-------
stuff here
some stuff
-------Title3-------
and some stuff
here
I want to find a certain keyword and for every finding I want to output the whole block between known delimiters. How can I do that? sed
fails me here.
Delimiters here are "------", but could be something else like numbers in [0-9]{8} format for example.
A similar problem which I couldn't solve is instead of outputting the contents of the block, output just the title of the block.
It seems to be easier to solve with perl
than sed