Thursday, December 24, 2020

Re: Substitute pattern over multiple lines



On Thursday, 24 December 2020 at 16:01:35 UTC-4 stevelitt wrote:
On Wed, 23 Dec 2020 21:16:20 -0400
John Cordes <john....@dal.ca> wrote:


> One big problem with the first part is that I *only* want to
> concatenate the continuation lines when they appear immediately
> following a "2 NOTE..." tag, AND that "2 NOTE" tag must be either the
> next or next but one line after "2 TYPE tngnote".
>
> I neglected to make it clear earlier that I need to first search on
> "2 TYPE tngnote" since there are other "2 TYPE" tags where I don't
> want to change anything.

Personally I'd do this as an AWK program (not an AWK one-liner). Have a
variable that gets incremented once when you hit "2 NOTE tngnote", gets
incremented again when you hit a "2 NOTE" 1 or 2 lines below, and
incremented again when you hit "3 CONC". If you increment twice like
this, you remove the "3 CONC" from the beginning of the each "3 CONC"
line and output it. At the end of the continuations, you put a </div>.
This requires that you put the corresponding <div> just before you
output the "2 NOTE" line.

If, at any time, you hit a line that forecloses the possibility of such
line-grafting, you drop the variable back to its original value.

It would also be very easy in Python, Python's advantage is that it can
easily store lines and "look back" before printing them. AWK can do
that, but it's more difficult.

I know this is offtopic on this list, but I think any Vim or ex
solution that can be made will be fragile and difficult to understand.

 Steve,

  I do understand. I am quite sure that if I had asked my son for help with this we would have ended up with an AWK script. That has happened before for at least one vaguely similar sort of job (in the sense of storing lines and checking back). I just really like using Vim, even though my skills for the more advanced techniques are sadly lacking.
 I have intended for ages to learn Python (I know that it is generally said to be very easy to learn) but it hasn't happened - not sure it ever will.
 
 John

--
--
You received this message from the "vim_use" maillist.
Do not top-post! Type your reply below the text you are replying to.
For more information, visit http://www.vim.org/maillist.php

---
You received this message because you are subscribed to the Google Groups "vim_use" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vim_use+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/vim_use/ffbfce0c-725c-4794-8ae9-f60330de51d4n%40googlegroups.com.

No comments: