I'd like to write a script in sed to insert line to a file after all similar lines in the file. So I need to locate the last match for a pattern and insert immediately after it. It's very unlikely that this would be the last line in the file.
I've seen a number of solutions that employ multiple piped calls to sed or use other tools such as tac. These are not appropriate - I need a pure sed solution that can be embedded inside a larger script that makes other changes to the same file.
I've been searching for a while but suspect it isn't possible. I thought I'd ask on here before giving up!
In case specifics help explain, I want to locate the last "Include" directive in an Apache http.conf file and insert another one beneath the last one.