Re: Need help with narroely focused use case of Emacs
On 28 Jun 2024 14:04 -0500, from rowlett@access.net (Richard Owlett):
> I need to replace ANY occurrence of
> <span class="verse" id="V1">
> thru [at most]
> <span class="verse" id="V119">
> by
> <sup>
>
> I'm reformatting a Bible stored in HTML format for a particular set of
> vision impaired seniors (myself included). Each chapter is in its own file.
>
> How do I open a file.
> Do the above replacement.
> Save and close the file.
Ignoring the question about Emacs and focusing on the goal (your
question otherwise is an excellent example of a XY question), this is
not something regular expressions are very good at. However, since
it's presumably a once-only operation, I assume that you can live with
it being done in a suboptimal way in terms of performance.
In that case, assuming for simplicity that all the files are in a
single directory, you could try something similar to:
$ for v in $(seq 1 119); do sed -i 's,<span class="verse" id="V'$v'">,<sup>,g' ./*.html; done
Be sure to have a copy in case something goes wrong; and diff(1) a few
files afterwards to make sure that the result is as you intended.
Yes, it almost certainly can be done with a single sed (or other
similar tool) invocation where the regular expression matches
precisely what you want it to match. But unless this is something you
will do very often, I tend to prefer readability over being clever,
even if the readable version is somewhat less performant.
--
Michael Kjörling 🔗 https://michael.kjorling.se
“Remember when, on the Internet, nobody cared that you were a dog?”
Reply to: