I have a bunch of HTML files with empty <a> tags tied to unique page IDs. I'd like to replace each one with the same link but including the text of the ID visibly in the line (i.e. displayed within the <p>...</p> tags within which the <a> tags occur) and changing the class of the tag so I can format it in the CSS.
So what I have currently is tags like this occurring throughout text:
<a id="page_123" class="garbage1"></a>some text<a id="page_124" class="garbage2"></a>
And I want to replace it with:
<a id="page_123" class="pagenum"> 123 </a>some text<a id="page_124" class="pagenum"> 124 </a>
So that the resulting display is:
some text 123 some text 124 some text.
The class of each of these tags is not always the same but I want to change all of them to pagenum. The tag id is always of the form page_####, anywhere from 1 to 4 digits.
I'm way over my head on this. I've gotten as far as constructing a horrifying regex (I know, I know) to pick the pattern out of the files, which seems to work when I test via cat file1.html | grep -o "\Wa\sid..page.\d*.\sclass..\w*....a."—that returns every instance of the pattern and nothing else. I'm totally stuck trying to go from there to making the replacement happen.