I hope this question's use case is not too specific for asking this question on this site. I have a very straightforward problem, but I think it could help learn about more general approaches as well in working with search and replace methods through command line tools for others who may come across this question.
My problem:
I have a directory structure with a few thousand html files, and what I would like to do is this:
Whenever there is a tag with an id
attribute set I would like to add a class="anchor"
to it, or if there is already one or more classes, add the class "anchor" in addition.
So I would like to replace any
<someTag id="some-id">
with
<someTag id="some-id" class="anchor">
and any
<someTag id="some-id" class="some-class">
with
<someTag id="some-id" class="some-class anchor">
Of course there could be all kinds of attributes mixed in between, so I would need some kind of search and replace method that could recognize these things between pointed brackets correctly.
I am using Ubuntu, and so I have all kinds of command line tools like sed at my fingertips, but I am not very experienced in their usage. So it would be of much help to me if anyone with more experience in this would know a quick solution.
Thank you very much for reading and thinking about it and it would be great if you have any suggestions.