title: search and replace/add some tag attributes in html files recursively
body: <p>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.</p>
  
  <p><strong>My problem:</strong></p>
  
  <p>I have a directory structure with a few thousand html files, and what I would like to do is this:</p>
  
  <p>Whenever there is a tag with an <code>id</code> attribute set I would like to add a <code>class="anchor"</code> to it, or if there is already one or more classes, add the class "anchor" in addition.</p>
  
  <p>So I would like to replace any</p>
  
  <p><code>&lt;someTag id="some-id"&gt;</code></p>
  
  <p>with </p>
  
  <p><code>&lt;someTag id="some-id" class="anchor"&gt;</code></p>
  
  <p>and any </p>
  
  <p><code>&lt;someTag id="some-id" class="some-class"&gt;</code></p>
  
  <p>with</p>
  
  <p><code>&lt;someTag id="some-id" class="some-class anchor"&gt;</code></p>
  
  <p>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.</p>
  
  <p>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.</p>
  
  <p>Thank you very much for reading and thinking about it and it would be great if you have any suggestions.</p>