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.
$ 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.
Pluma is my editor of choice.
*BUT* it can NOT handle Search and Replace operations involving regular expressions.
Emacs can. It has much verbose documentation.
But examples seem rather scarce.
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.
Le 28/06/2024 à 21:04, Richard Owlett a écrit :
Pluma is my editor of choice.[...]
*BUT* it can NOT handle Search and Replace operations involving regular expressions.
Hello Richard,
According to the Mate wiki, Pluma handles regular expressions the Perl way: https://wiki.mate-desktop.org/mate-desktop/applications/pluma/ https://perldoc.perl.org/perlre
Le 28/06/2024 à 21:04, Richard Owlett a écrit :
Pluma is my editor of choice.[...]
*BUT* it can NOT handle Search and Replace operations involving
regular expressions.
Hello Richard,
According to the Mate wiki, Pluma handles regular expressions the Perl way: https://wiki.mate-desktop.org/mate-desktop/applications/pluma/
https://perldoc.perl.org/perlre
On Fri, 2024-06-28 at 14:04 -0500, Richard Owlett wrote:
Pluma is my editor of choice.
*BUT* it can NOT handle Search and Replace operations involving
regular
expressions.
Emacs can. It has much verbose documentation.
But examples seem rather scarce.
nedit can handle regular expressions in search and replace operations.
I find nedit easier to use than 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.
On Fri, 28 Jun 2024 20:53:50 +0000
Michael Kjörling <c9bc136c6063@ewoof.net> wrote:
$ 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.
Having done that (or similar), don't forget to change the relevant
</span> closing tags to </sup> closing tags. However, there may be
other </span> closing tags you don't want to change because they close
other <span> tags we haven't seen.
So you may prefer to use regexes as
Murphy intended, handling both the opening and closing tags at the same
time, leaving the intervening text intact.
On Fri, Jun 28, 2024 at 02:04:37PM -0500, Richard Owlett wrote:
Pluma is my editor of choice.
*BUT* it can NOT handle Search and Replace operations involving regular
expressions.
I would be *very* surprised if an editor, these days and age
can't do regular expressions. Really.
Emacs can. It has much verbose documentation.
But examples seem rather scarce.
Of course, Emacs is the best editor out there, by a long shot.
But learning it is a long and panoramic road. You should at
least have a rough idea that you want to take it.
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.
Two ways of skinning that cat:
- in a terminal, type "emacs <yourfilename>"
- in an open Emacs instance (be it terminal or GUI, your
choice), type C-x C-f (hold CTRL, then "x", while holding
CTRL then "f"). You get a prompt in the bottom line (the
so-called minibuffer), enter your file name there. You
get tab completions.
Then there are menus...
Do the above replacement.
Go to the top of your buffer (this is what you would call
"your file": Emacs calls the things which hold your text
while you are on them "buffers").
Do M-x (hold Meta, most of the time your Alt key, then "x").
You get a command for a prompt. Enter "query-replace-regexp"
(you get tab completions, so "que" TAB "re" TAB should suffice,
roughly speaking). Enter the regular expression you're looking
for. Then ENTER, then your replacement.
Save and close the file.
To save, C-x C-s. I don't quite know what you mean by
"close".
To quit Emacs, C-x C-c.
Now I don't quite understand what you mean above with your
example, and whether it can be expressed by a regular expression
at all, but that is for a second go.
First, find out whether your beloved Pluma can deliver. I'm
sure it can. Unless you want to embark in the Emacs adventure
(very much recommended, mind you, but not the most efficient
path to your problem at hand).
Cheers
On 06/28/2024 03:53 PM, Michael Kjrling wrote:
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
Emacs *CAN NOT* be ignored.
It is the _available_ editor known to be capable of handling regular expressions.
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.
HUH ??????????
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
I'll have to investigate sed further.
My project is not yet to the point of automatically editing ALL chapters. I need to first establish how to edit all VERSES of an individual chapter.
ROFL ;} No one would define me as a "programmer". I took an introduction to computers course as a E.E. student in the 60's. Most of my jobs required background in component level analog electronics. Got one assignment because I was not "afraid" of 8080 ;}
On 06/28/2024 03:53 PM, Michael Kjörling wrote:
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
Emacs *CAN NOT* be ignored.
It is the _available_ editor known to be capable of handling regular expressions.
On Fri, 28 Jun 2024 20:53:50 +0000
Michael Kjrling <c9bc136c6063@ewoof.net> wrote:
$ 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.
Having done that (or similar), don't forget to change the relevant
</span> closing tags to </sup> closing tags. However, there may be
other </span> closing tags you don't want to change because they close
other <span> tags we haven't seen. So you may prefer to use regexes as
Murphy intended, handling both the opening and closing tags at the same
time, leaving the intervening text intact.
Richard Owlett <rowlett@access.net> wrote:
On 06/28/2024 03:53 PM, Michael Kjörling wrote:
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
Emacs *CAN NOT* be ignored.
It is the _available_ editor known to be capable of handling regular
expressions.
Err, pluma is available I believe.
On 06/28/2024 02:04 PM, Richard Owlett wrote:
Pluma is my editor of choice.I've never used it but I just
started it and used the Replace... entry on the Search menu to bring up
a dialog box. In the dialog box there is a tick box labelled "Match
regular expression". So I ticked that and then tested it by editing an
html file using an RE.
So Pluma is an "_available_ editor known to be capable of handling
regular expressions."
And as others have pointed out, sed is available and it's easy to
install others. So there are many possible answers to your question
other than emacs.
The option "g" means that said should do this multiple times if
it occurs in the same file (globally, like grep) instead of the
default behavior which is to find the first match and just
change that.
$ for v in $(seq 1 119); do sed -i 's,<span class="verse" id="V'$v'">,<sup>,g' ./*.html; done
Having done that (or similar), don't forget to change the relevant
</span> closing tags to </sup> closing tags. However, there may be
other </span> closing tags you don't want to change because they close
other <span> tags we haven't seen.
Chuckle ;} The appropriate "</span>" to be replaced by "</sup>" is ALWAYS preceded by "#160;" .
On 29 Jun 2024 06:12 -0500, from rowlett@access.net (Richard Owlett):
there may be other </span> closing tags you don't want to
change because they close other <span> tags we haven't seen.
Chuckle ;} The appropriate "</span>" to be replaced by "</sup>" is ALWAYS preceded by "#160;" .
As far as I can see, neither of this was stated in the original
question. Please don't add arbitrary requirements later to invalidate potential answers.
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.
HUH ??????????
..._focus on the goal_.
On 2024-06-29, Michael Kjörling <c9bc136c6063@ewoof.net> wrote:
HUH ??????????
..._focus on the goal_.
Owlett is a notorious troll who never listens to reason.
When searching for information on regular expressions I came across one that did it by searching for
{"1 thru 9" OR "10 thru 99" OR "100 thru 999"} .
I lost the reference ;<
Owlett is a notorious troll who never listens to reason.
This is wrong, borderline defamatory. Richard Owlett is not a
On 2024-06-28 20:53:50 +0000, Michael Kjörling wrote:
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.
To match a range inside a regexp, $(rgxg range 1 119) is readable. :)
rgxg is provided by the package of the same name.
Oh, I see what the question was.
There is "use regular expressions", "use multi line matching" in Geany
I'm not very good at regular expressions.
I'd probably do it 3 times
"search for" <span class="verse" id="V(...)">
"search for" <span class="verse" id="V(..)">
"search for" <span class="verse" id="V(.)">
got it thanks.
<span class="verse" id="V[0-7]{1,2}">
<sup>
<sup>
<sup>
<span class="verse" id="V19">
<span class="verse" id="V129">
<span class="verse" id="V138">
Do you have a book whose verses are enumerated in octal?
On Sat, Jun 29, 2024 at 06:37:23AM -0500, Richard Owlett wrote:
[...]
When searching for information on regular expressions I came across one that >> did it by searching for
{"1 thru 9" OR "10 thru 99" OR "100 thru 999"} .
I lost the reference ;<
That would be something like ([0-9]|[1-9][0-9]|[1-9][0-9][0-9])
since [x-y] expresses a range of characters, the | does OR and
the () do grouping [1].
If you allow yourself to be a bit sloppy [2], and allow numbers
with leading zeros, many regexps flavors have the "limited count
operator" {min,max}, with which you might say [0-9]{1,3} (you
won't need the grouping here, since the repeat operator binds
strongly enough to not mess up the rest of your regexp.
CAVEAT IMPLEMENTOR: Depending on the flavor of your regexps, the
() and sometimes the | need a backslash in front to give them
their magic meaning. In Emacs they do, in Perl (and PCRE, which
is most probably the engine behind Pluma) they don't. In grep
(and sed) you can switch behavior with an option (-E was it,
IIRC).
Cheers
[1] This grouping is (again, depening on your regexp flavour)
a "capturing grouping", meaning that you can refer later
to what was matched by the sub-expression in the parens.
There are also (flavor blah blah) non-capturing groupings.
[2] You always are somewhat sloppy with regexps. Actually you
are being sloppy already, since every classical textbook
will tell you that they totally suck at understanding
"nested stuff", which HTML is, alas. But under the right
conditions they can butcher it alright :-)
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (0 / 16) |
Uptime: | 165:40:59 |
Calls: | 10,385 |
Calls today: | 2 |
Files: | 14,057 |
Messages: | 6,416,525 |