I need to get the HTML contents between a pair of given tags using a bash script. As an example, having the HTML code below:
BASH is probably the wrong tool for this. Try a Python script using the powerful Beautiful Soup library instead.
It will be more work upfront but in the long run (here: after one hour), the time savings will make up for the additional effort.