I have read the following post about How to match content between HTML specific tags with attribute using grep?. However, when I use the code derived from that page, I'm unable to match the content. I keep getting a blank output.
Here's the code I'm using:
grep -oP '(?<=<div class="tag"> ).*?(?= </tag>)' file1.txt
I've ensured that all the line endings are in linux (LF).
Here's file1.txt:
<div class="tag">
<p>hello world!</p>
</tag><!-- .end-section -->
I would want the output:
<div class="tag">
<p>hello world!</p>
</tag>
Does anyone know why I can't match the content between these lines? I have tried everything that I can think of. Your insight and support is highly appreciated.