Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > linux.debian.user > #270558 > unrolled thread
| Started by | Richard Owlett <rowlett@access.net> |
|---|---|
| First post | 2024-06-28 21:10 +0200 |
| Last post | 2024-06-29 12:10 +0200 |
| Articles | 20 on this page of 39 — 17 participants |
Back to article view | Back to linux.debian.user
Need help with narroely focused use case of Emacs Richard Owlett <rowlett@access.net> - 2024-06-28 21:10 +0200
Re: Need help with narroely focused use case of Emacs didier gaumet <didier.gaumet@gmail.com> - 2024-06-28 21:20 +0200
Re: Need help with narroely focused use case of Emacs <tomas@tuxteam.de> - 2024-06-29 07:00 +0200
Re: Need help with narroely focused use case of Emacs Richard Owlett <rowlett@access.net> - 2024-06-29 12:10 +0200
Re: Need help with narroely focused use case of Emacs Michael Kjörling <c9bc136c6063@ewoof.net> - 2024-06-28 23:00 +0200
Re: Need help with narroely focused use case of Emacs Charles Curley <charlescurley@charlescurley.com> - 2024-06-29 05:30 +0200
Re: Need help with narroely focused use case of Emacs Richard Owlett <rowlett@access.net> - 2024-06-29 13:20 +0200
Re: Need help with narroely focused use case of Emacs Michael Kjörling <c9bc136c6063@ewoof.net> - 2024-06-29 15:50 +0200
Re: Need help with narroely focused use case of Emacs Andy Smith <andy@strugglers.net> - 2024-06-29 16:20 +0200
Re: Need help with narroely focused use case of Emacs Lee <ler762@gmail.com> - 2024-06-29 18:10 +0200
Re: Need help with narroely focused use case of Emacs Greg Wooledge <greg@wooledge.org> - 2024-06-29 14:50 +0200
Re: Need help with narroely focused use case of Emacs Richard Owlett <rowlett@access.net> - 2024-06-29 13:00 +0200
Re: Need help with narroely focused use case of Emacs debian-user@howorth.org.uk - 2024-06-29 14:00 +0200
Re: Need help with narroely focused use case of Emacs Richard Owlett <rowlett@access.net> - 2024-06-29 15:00 +0200
Re: Need help with narroely focused use case of Emacs Dan Ritter <dsr@randomstring.org> - 2024-06-29 14:10 +0200
Re: Need help with narroely focused use case of Emacs Greg Wooledge <greg@wooledge.org> - 2024-06-29 15:00 +0200
Re: Need help with narroely focused use case of Emacs Michael Kjörling <c9bc136c6063@ewoof.net> - 2024-06-29 15:50 +0200
Re: Need help with narroely focused use case of Emacs Curt <curty@free.fr> - 2024-06-29 18:10 +0200
Re: Need help with narroely focused use case of Emacs <tomas@tuxteam.de> - 2024-06-29 19:00 +0200
Re: Need help with narroely focused use case of Emacs Curt <curty@free.fr> - 2024-06-29 19:50 +0200
Curt having his fits [was: Need help with narroely focused use case of Emacs] <tomas@tuxteam.de> - 2024-06-29 20:00 +0200
Re: Curt having his fits [was: Need help with narroely focused use case of Emacs] Curt <curty@free.fr> - 2024-06-29 20:50 +0200
Re: Curt having his fits [was: Need help with narroely focused use case of Emacs] Richard <rrosner5@gmail.com> - 2024-06-30 01:00 +0200
Re: Curt having his fits [was: Need help with narroely focused use case of Emacs] Greg Wooledge <greg@wooledge.org> - 2024-06-30 01:10 +0200
Re: Curt having his fits [was: Need help with narroely focused use case of Emacs] Will Mengarini <seldon@eskimo.com> - 2024-06-30 01:40 +0200
Re: Curt having his fits Geert Stappers <stappers@stappers.nl> - 2024-06-30 11:50 +0200
Eric Naggum [was: Curt having his fits] <tomas@tuxteam.de> - 2024-06-30 14:00 +0200
Re: Need help with narroely focused use case of Emacs Vincent Lefevre <vincent@vinc17.net> - 2024-06-29 17:10 +0200
Re: Need help with narroely focused use case of Emacs David Wright <deblis@lionunicorn.co.uk> - 2024-06-29 21:00 +0200
Re: Need help with narroely focused use case of Emacs <tomas@tuxteam.de> - 2024-06-29 06:50 +0200
Re: Need help with narroely focused use case of Emacs Richard Owlett <rowlett@access.net> - 2024-06-29 13:40 +0200
Re: Need help with narroely focused use case of Emacs <tomas@tuxteam.de> - 2024-06-29 19:20 +0200
Solution [Re: Need help with narroely focused use case of Emacs] Richard Owlett <rowlett@access.net> - 2024-07-05 14:10 +0200
Re: Need help with narroely focused use case of Emacs Max Nikulin <manikulin@gmail.com> - 2024-06-29 13:40 +0200
Re: Need help with narroely focused use case of Emacs Max Nikulin <manikulin@gmail.com> - 2024-06-29 17:10 +0200
Re: Need help with narroely focused use case of Emacs Greg Wooledge <greg@wooledge.org> - 2024-06-29 21:30 +0200
Re: Need help with narroely focused use case of Emacs Greg Wooledge <greg@wooledge.org> - 2024-06-30 15:30 +0200
Re: Need help with narroely focused use case of Emacs Andy Smith <andy@strugglers.net> - 2024-06-30 16:00 +0200
Re: Need help with narroely focused use case of Emacs Richard Owlett <rowlett@access.net> - 2024-06-29 12:10 +0200
Page 1 of 2 [1] 2 Next page →
| From | Richard Owlett <rowlett@access.net> |
|---|---|
| Date | 2024-06-28 21:10 +0200 |
| Subject | Need help with narroely focused use case of Emacs |
| Message-ID | <IUp8S-6gVm-9@gated-at.bofh.it> |
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.
Help please.
TIA
[toc] | [next] | [standalone]
| From | didier gaumet <didier.gaumet@gmail.com> |
|---|---|
| Date | 2024-06-28 21:20 +0200 |
| Message-ID | <IUpix-6gYT-3@gated-at.bofh.it> |
| In reply to | #270558 |
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
[toc] | [prev] | [next] | [standalone]
| From | <tomas@tuxteam.de> |
|---|---|
| Date | 2024-06-29 07:00 +0200 |
| Message-ID | <IUylP-6mQE-5@gated-at.bofh.it> |
| In reply to | #270559 |
[Multipart message — attachments visible in raw view] — view raw
On Fri, Jun 28, 2024 at 09:17:14PM +0200, didier gaumet wrote: > 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 See? I was sure of that. And Perl style regexps are actually somewhat friendlier than Emacs style (they're roughly one decennium younger). Thanks, Didier :-) Cheers -- t
[toc] | [prev] | [next] | [standalone]
| From | Richard Owlett <rowlett@access.net> |
|---|---|
| Date | 2024-06-29 12:10 +0200 |
| Message-ID | <IUDbP-6q3V-1@gated-at.bofh.it> |
| In reply to | #270559 |
On 06/28/2024 02:17 PM, didier gaumet wrote: > 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/ Hadn't seen that page. I based my opinion on what I saw when doing a Search and Replace. Also Pluma's Help function doesn't mention it. > https://perldoc.perl.org/perlre That page is thin on examples. But now knowing that Pluma does things "the Perl way" I can do a web search. Thank you.
[toc] | [prev] | [next] | [standalone]
| From | Michael Kjörling <c9bc136c6063@ewoof.net> |
|---|---|
| Date | 2024-06-28 23:00 +0200 |
| Message-ID | <IUqRj-6hMu-1@gated-at.bofh.it> |
| In reply to | #270558 |
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?”
[toc] | [prev] | [next] | [standalone]
| From | Charles Curley <charlescurley@charlescurley.com> |
|---|---|
| Date | 2024-06-29 05:30 +0200 |
| Message-ID | <IUwWJ-6lBQ-3@gated-at.bofh.it> |
| In reply to | #270567 |
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. -- Does anybody read signatures any more? https://charlescurley.com https://charlescurley.com/blog/
[toc] | [prev] | [next] | [standalone]
| From | Richard Owlett <rowlett@access.net> |
|---|---|
| Date | 2024-06-29 13:20 +0200 |
| Message-ID | <IUEhM-6qLW-337@gated-at.bofh.it> |
| In reply to | #270577 |
On 06/28/2024 10:23 PM, Charles Curley wrote: > 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. Chuckle ;} The appropriate "</span>" to be replaced by "</sup>" is ALWAYS preceded by "#160;" . > 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. In this particular case I suspect it would become overly complex. I've already discovered that the order of edits is important.
[toc] | [prev] | [next] | [standalone]
| From | Michael Kjörling <c9bc136c6063@ewoof.net> |
|---|---|
| Date | 2024-06-29 15:50 +0200 |
| Message-ID | <IUGCK-6s5g-7@gated-at.bofh.it> |
| In reply to | #270585 |
On 29 Jun 2024 06:12 -0500, from rowlett@access.net (Richard Owlett): >>> $ 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;" . 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. -- Michael Kjörling 🔗 https://michael.kjorling.se “Remember when, on the Internet, nobody cared that you were a dog?”
[toc] | [prev] | [next] | [standalone]
| From | Andy Smith <andy@strugglers.net> |
|---|---|
| Date | 2024-06-29 16:20 +0200 |
| Message-ID | <IUH5L-6sus-3@gated-at.bofh.it> |
| In reply to | #270594 |
Hello, On Sat, Jun 29, 2024 at 01:46:27PM +0000, Michael Kjörling wrote: > 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. It's not an authentic Owlett thread unless it contains an enormous XY problem, a monomaniacal obsession with a solution already part-dreamed up by the OP, several factual errors, and a constant trickle of confounding small details that were never provided up front, now delivered with glee. Otherwise it's just sparkling timewasting. Thanks, Andy -- https://bitfolk.com/ -- No-nonsense VPS hosting
[toc] | [prev] | [next] | [standalone]
| From | Lee <ler762@gmail.com> |
|---|---|
| Date | 2024-06-29 18:10 +0200 |
| Message-ID | <IUIOe-6tyI-7@gated-at.bofh.it> |
| In reply to | #270585 |
Hi, > > 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. > > In this particular case I suspect it would become overly complex. > I've already discovered that the order of edits is important. I guess it depends on what you're used to. I don't think this bit is overly complex .. your opinion might be different $ cat /tmp/z cat /dev/null > txtfile.html for v in $(seq 1 12); do echo '<span class="verse" id="V'$v'"> text text text </span>' >> txtfile.html; done sed -Ei.bak 's@<span class="verse" id="V[[:digit:]]+">([^<]*)</span>@<sup>\1</sup>@g' txtfile.html $ bash z $ cat txtfile* <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <sup> text text text </sup> <span class="verse" id="V1"> text text text </span> <span class="verse" id="V2"> text text text </span> <span class="verse" id="V3"> text text text </span> <span class="verse" id="V4"> text text text </span> <span class="verse" id="V5"> text text text </span> <span class="verse" id="V6"> text text text </span> <span class="verse" id="V7"> text text text </span> <span class="verse" id="V8"> text text text </span> <span class="verse" id="V9"> text text text </span> <span class="verse" id="V10"> text text text </span> <span class="verse" id="V11"> text text text </span> <span class="verse" id="V12"> text text text </span> $ Regards, Lee
[toc] | [prev] | [next] | [standalone]
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Date | 2024-06-29 14:50 +0200 |
| Message-ID | <IUFGF-6rwu-1@gated-at.bofh.it> |
| In reply to | #270577 |
On Fri, Jun 28, 2024 at 21:23:03 -0600, Charles Curley wrote: > 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. https://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags#answer-1732454
[toc] | [prev] | [next] | [standalone]
| From | Richard Owlett <rowlett@access.net> |
|---|---|
| Date | 2024-06-29 13:00 +0200 |
| Message-ID | <IUDYh-6qlC-129@gated-at.bofh.it> |
| In reply to | #270567 |
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. > 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. > > 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. 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 ;} > > 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. >
[toc] | [prev] | [next] | [standalone]
| From | debian-user@howorth.org.uk |
|---|---|
| Date | 2024-06-29 14:00 +0200 |
| Message-ID | <IUEUh-6qZN-5@gated-at.bofh.it> |
| In reply to | #270584 |
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. 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.
[toc] | [prev] | [next] | [standalone]
| From | Richard Owlett <rowlett@access.net> |
|---|---|
| Date | 2024-06-29 15:00 +0200 |
| Message-ID | <IUFQl-6rzP-1@gated-at.bofh.it> |
| In reply to | #270588 |
On 06/29/2024 06:51 AM, debian-user@howorth.org.uk wrote: > 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. May I quote my original post? > 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." So you evidently have a later version than I have available for this particular machine. One does get latest and greatest by simply wishing for it. > > 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. My definition of "available" includes knowledge of how to use it. I've investigated it for some past projects and found easier way to accomplish those particular tasks. Part of my interest in Emacs stems from having seen what co-workers could do with its predecessor TECO decades ago. Updating MY system is NONtrivial!
[toc] | [prev] | [next] | [standalone]
| From | Dan Ritter <dsr@randomstring.org> |
|---|---|
| Date | 2024-06-29 14:10 +0200 |
| Message-ID | <IUF3Y-6rij-9@gated-at.bofh.it> |
| In reply to | #270584 |
Richard Owlett 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. If your machine doesn't have sed, it is not a working Debian system. Every Debian machine comes with sed by default. Even the rescue image has sed. The installer environment, before Debian is actually installed, has sed. sed is a basic tool that everyone has access to. emacs needs to be installed, and often is not. I know from past experience that it's useless to offer you any solution that deviates from the vision you have for the way the world ought to work, but this is a sufficiently common kind of problem that a full answer will be useful to other people. > > 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 ?????????? An XY question is when someone asks "How can I do specific thing X?" but what they want to do is task Y, which is more easily accomplished in a different way that doesn't involve X at all. Usually this means that they have read something that tells them about X in a different context, and they think that is an essential part of solving their Y problem. If we're lucky, they tell us what Y is. Frequently, XY questions just show up as "How do I do X?" without context. It happens a lot on this mailing list. Or, maybe your expression of disbelief was about regular expressions? A regular expression (regexp) is a specific kind of formal language for specifying a pattern of tokens -- what we often call a "string". If the regexp describes a candidate string, we call that a "match". A common editing task is to find all the matches for a regexp and replace them with some other string. The program "grep" takes its name from a sequence of editor commands: global regular expression print. Michael says that regexps aren't great at this particular task because there's a variable component in the pattern which is hard to describe. He comes up with a clever solution based on the fact that the variable component is going to be an integer sequence. > > 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 This sets up a loop which will execute 119 times, incrementing the variable $v from 1 to 119. Inside the loop, it calls `sed` to execute inplace (-i) which means it will change the files it encounters rather than spitting out new files on standard out. The command passed to sed is s,<span class="verse" id="V'$v'">,<sup>,g s means string substitution. It takes a pattern, a replacement, and options, separated by the next character after the s, which in this case is a comma. <span class="verse" id="V$v"> is the pattern. Because of the loop, the value $v is going to be replaced by the shell before sed sees this, so on various runs through the loop sed will see: <span class="verse" id="V1"> <span class="verse" id="V2"> ... <span class="verse" id="V118"> <span class="verse" id="V119"> You'll probably need to adjust this for other books. Anyway, whenever sed sees the pattern above, it will replace it with: <sup> which is what you said you wanted. 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. ./*.html tells sed to operate on all the files in the current directory ending in .html -- yes, shells implement a version of regexp for file pattern matching. And that's the end of the loop. > 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. The solution Michael presented can be run on just one file instead of all the .html files in the current directory. > 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 ;} The true UNIX philosophy is that at any moment, any user can stop being "just a user" and use the tools present to do some programming to solve their problems. -dsr-
[toc] | [prev] | [next] | [standalone]
| From | Greg Wooledge <greg@wooledge.org> |
|---|---|
| Date | 2024-06-29 15:00 +0200 |
| Message-ID | <IUFQl-6rzP-7@gated-at.bofh.it> |
| In reply to | #270589 |
On Sat, Jun 29, 2024 at 07:43:47 -0400, Dan Ritter wrote: > 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. The g option in sed's s command means it will apply the substitution multiple times per *line*. Not per file. It always applies multiple times per file, unless you restrict the line range with a prefix. hobbit:~$ printf 'foo foo\nfoo foo\n' | sed s/foo/bar/ bar foo bar foo hobbit:~$ printf 'foo foo\nfoo foo\n' | sed s/foo/bar/g bar bar bar bar
[toc] | [prev] | [next] | [standalone]
| From | Michael Kjörling <c9bc136c6063@ewoof.net> |
|---|---|
| Date | 2024-06-29 15:50 +0200 |
| Message-ID | <IUGCK-6s5g-5@gated-at.bofh.it> |
| In reply to | #270584 |
On 29 Jun 2024 05:51 -0500, from rowlett@access.net (Richard Owlett): >> Ignoring the question about Emacs > > Emacs *CAN NOT* be ignored. I did not say to ignore _Emacs_. I said that I was ignoring the _question_ about Emacs, to instead... >> 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 ?????????? ..._focus on the goal_. (It is usually a good idea to read at least a whole sentence before responding to it.) The _goal_ in this case being your stated specific series of string replacements. If you want to use Emacs to do that, no one is stopping you from doing so. You can directly adapt what I suggested to an Emacs workflow. But just because a nailgun can be used to hang a painting doesn't mean that a nailgun is the _appropriate_ tool for that particular job; without detracting from its usability in _other_ applications. Sometimes really all you are looking for is a small hammer. -- Michael Kjörling 🔗 https://michael.kjorling.se “Remember when, on the Internet, nobody cared that you were a dog?”
[toc] | [prev] | [next] | [standalone]
| From | Curt <curty@free.fr> |
|---|---|
| Date | 2024-06-29 18:10 +0200 |
| Message-ID | <IUIOe-6tyI-5@gated-at.bofh.it> |
| In reply to | #270593 |
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. But you people adore this kind of troll, inexplicably, perhaps because he allows you to expand endlessly on your reams of essentially useless knowledge.
[toc] | [prev] | [next] | [standalone]
| From | <tomas@tuxteam.de> |
|---|---|
| Date | 2024-06-29 19:00 +0200 |
| Message-ID | <IUJAB-6tQ0-7@gated-at.bofh.it> |
| In reply to | #270600 |
[Multipart message — attachments visible in raw view] — view raw
On Sat, Jun 29, 2024 at 04:02:56PM -0000, Curt wrote: > 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. This is wrong, borderline defamatory. Richard Owlett is not a troll [1]. He may be uncommon in the way he approaches things, and I do understand his ways may annoy some people. If they annoy you, you always may choose to not respond. Others will chime in. Much more polite and much more effective for the whole mailing list. Lobbing insults at people doesn't help anyone. Cheers [1] by the very definition of "troll", who isn't interested in the topic itself, but just in eliciting a response. -- t
[toc] | [prev] | [next] | [standalone]
| From | Curt <curty@free.fr> |
|---|---|
| Date | 2024-06-29 19:50 +0200 |
| Message-ID | <IUKmZ-6ulN-1@gated-at.bofh.it> |
| In reply to | #270605 |
On 2024-06-29, <tomas@tuxteam.de> <tomas@tuxteam.de> wrote: > >> Owlett is a notorious troll who never listens to reason. > > This is wrong, borderline defamatory. Richard Owlett is not a Andy Smith: It's not an authentic Owlett thread unless it contains an enormous XY problem, a monomaniacal obsession with a solution already part-dreamed up by the OP, several factual errors, and a constant trickle of confounding small details that were never provided up front, now delivered with glee. IOW, a troll. So go fuck yourself, as you should have done years ago. Defamatory. What are you, a fucking lawyer? Sue me then, you little snit.
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | linux.debian.user
csiph-web