Delete string and next two lines and repeat ?



  • @Terry-Gaff,

    You don’t even need a macro. It’s a simple regular expression replace-all:

    Given the data set:

    ISS (ZARYA)
    1 25544U 98067A 19059.58113039 .00000585 00000-0 16781-4 0 9999
    2 25544 51.6423 181.2243 0003698 63.9072 32.5537 15.52745983158386
    TBA - TO BE ASSIGNED
    1 81052U 19052.87930724 +.00000771 +00000-0 +28838-3 0 9990
    2 81052 065.7839 018.1627 0642041 054.4978 311.4249 13.59874992784151
    ISS (ZARYA)
    1 25544U 98067A 19059.58113039 .00000585 00000-0 16781-4 0 9999
    2 25544 51.6423 181.2243 0003698 63.9072 32.5537 15.52745983158386
    TBA - TO BE ASSIGNED
    1 81052U 19052.87930724 +.00000771 +00000-0 +28838-3 0 9990
    2 81052 065.7839 018.1627 0642041 054.4978 311.4249 13.59874992784151
    ISS (ZARYA)
    1 25544U 98067A 19059.58113039 .00000585 00000-0 16781-4 0 9999
    2 25544 51.6423 181.2243 0003698 63.9072 32.5537 15.52745983158386
    TBA - TO BE ASSIGNED
    1 81052U 19052.87930724 +.00000771 +00000-0 +28838-3 0 9990
    2 81052 065.7839 018.1627 0642041 054.4978 311.4249 13.59874992784151
    
    • Find = TBA - TO BE ASSIGNED\R.*\R.*(\R|\Z)
    • Replace = (empty)
    • Search Mode = regular expression
    • Replace All

    It grabs the line, and the two subsequent lines (with their line endings), and replaces all three lines with nothing (ie, deletes them). The end result of a single Replace All is

    ISS (ZARYA)
    1 25544U 98067A 19059.58113039 .00000585 00000-0 16781-4 0 9999
    2 25544 51.6423 181.2243 0003698 63.9072 32.5537 15.52745983158386
    ISS (ZARYA)
    1 25544U 98067A 19059.58113039 .00000585 00000-0 16781-4 0 9999
    2 25544 51.6423 181.2243 0003698 63.9072 32.5537 15.52745983158386
    ISS (ZARYA)
    1 25544U 98067A 19059.58113039 .00000585 00000-0 16781-4 0 9999
    2 25544 51.6423 181.2243 0003698 63.9072 32.5537 15.52745983158386
    

    -----
    Boilerplate I add to most regex questions that I answer:

    This forum is formatted using Markdown, with a help link buried on the little grey ? in the COMPOSE window/pane when writing your post. For more about how to use Markdown in this forum, please see @Scott-Sumner’s post in the “how to markdown code on this forum” topic, and my updates near the end. It is very important that you use these formatting tips – using single backtick marks around small snippets, and using code-quoting for pasting multiple lines from your example data files – because otherwise, the forum will change normal quotes ("") to curly “smart” quotes (“”), will change hyphens to dashes, will sometimes hide asterisks (or if your text is c:\folder\*.txt, it will show up as c:\folder*.txt, missing the backslash). If you want to clearly communicate your text data to us, you need to properly format it.

    If you have further search-and-replace (“matching”, “marking”, “bookmarking”, regular expression, “regex”) needs, study this FAQ and the documentation it points to. Before asking a new regex question, understand that for future requests, many of us will expect you to show what data you have (exactly), what data you want (exactly), what regex you already tried (to show that you’re showing effort), why you thought that regex would work (to prove it wasn’t just something randomly typed), and what data you’re getting with an explanation of why that result is wrong. When you show that effort, you’ll see us bend over backward to get things working for you. If you need help formatting, see the paragraph above.

    Please note that for all regex and related queries, it is best if you are explicit about what needs to match, and what shouldn’t match, and have multiple examples of both in your example dataset. Often, what shouldn’t match helps define the regular expression as much or more than what should match.



  • a little explanation if you are interested:
    ^defines that TBA - TO BE ASSIGNED has to be at the beginning.
    the first (.*?)\Rdefines that you can have any text after TBA - TO BE ASSIGNED until the end of the line.
    each (.*?)\R marks the following line, regardless of it’s contents.
    the string token (.*?) is a “non greedy” wild card and \R is a token for any form of line ending, either cr, lf, or cr+lf



  • @PeterJones

    damned, why didn’t we see each other writing at the same time ?
    sometimes the ajax just gets stuck and i don’t see people already typing.
    my apologies, i usually never post if i see that you or another regular is already typing.



  • @Meta-Chuh said:

    why didn’t we see each other writing at the same time

    I didn’t even see you in the topic, let alone typing. @Terry-R popped in and out a couple times, but I never saw him start typing, which is why I continued going. AJAX is imperfect, I guess. :-)

    And ++ for including the macro the OP asked for. :-)



  • @Meta-Chuh

    Hey, this happens to me also.
    I, mostly, don’t see anyone typing or reading and then when I’m posting, another post has just arrived already.
    Thought this might be related with my setup but now …



  • hahhh, i can see @Terry-R typing now, but only terry, not even myself … terry, what did you do ;-)
    just kidding …



  • @PeterJones said:

    @Terry-R popped in and out a couple times

    I was about to type but got beaten both by yourself and @Meta-Chuh

    And good idea @PeterJones explaining the “replace-all” to OP. I suspect he hadn’t actually realised that that means a macro would NOT be needed.

    Funnily enough I had originally setup my forum profile to be ‘hidden’, only now I’m not when online, and can’t see the option I’d originally set.

    I prefer to be anonymous and be able to ‘pounce’ at a moments notice!

    Terry



  • @Terry-R

    Funnily enough I had originally setup my forum profile to be ‘hidden’, only now I’m not when online, and can’t see the option I’d originally set.
    I prefer to be anonymous and be able to ‘pounce’ at a moments notice!

    you will be hidden for everyone as long as you just read, but afaik, once you start typing, you will be seen by all senior members, mods or admins, even if you are still set as invisible.



  • @Meta-Chuh said:

    you will be seen by all senior members, mods or admins

    I understand mods and admins, but who ranks as a senior member?

    Terry



  • @Terry-R

    if you check for yourself, and you are able to see everyone who’s typing, even though you know they are set to invisible, you can already consider yourself a senior member.
    if you are able to create a faq topic, you are a trusted vip senior member.
    if you are able to create an announcement, you are god 😉

    ps: if i see you typing an answer to a topic, i would never answer myself before reading yours. and as soon as i read yours, it doesn’t make any sense to answer at all with my janitor regex knowledge, as anything i could write would be baby-poo, so to speak ;-)



  • @Meta-Chuh
    Your replies are far from being baby-poo. I will sometimes still reply to an OP, even after reading someone else’s post, if I believe I can fill in some gaps, or perhaps provide an alternative idea/concept.
    And I welcome other members feedback or alternatives to my solutions.

    My motto
    The day you stop learning is the day you die

    Terry



  • @Terry-R

    thanks for your words.

    I will sometimes still reply to an OP, even after reading someone else’s post, if I believe I can fill in some gaps, or perhaps provide an alternative idea/concept.

    yes, you are absolutely correct and encouraged to do so any time, so please don’t stop that.
    the only thing i wanted to tell you in person (albeit being typed), is that every single post i have read from you, leaves nothing open from my point of view.

    ps: no boot licking whatsoever.
    you have seen that i give my second opinion to some posts, but for now never to yours.
    just a little kudos from my part and this was an opportunity to do so.

    The day you stop learning is the day you die

    i second that completely, as i can see some “walking dead” every once in a while … even though i don’t have a sixth sense that i know of ;-)



  • Hi, @terry-gaff, @terry-r, @meta-chuh, @peterjones, @eko-palypse and All

    An other syntax of the Peter’s search regex could be :

    (?-is)^TBA - TO BE ASSIGNED\R(.+(\R|\Z)){2}, which also grabs the 2 subsequent lines, along with the line TBA - TO BE ASSIGNED.

    Of course, the line, located, right after the line TBA - TO BE ASSIGNED, can never end with the \Z assertion, but it doesn’t matter !

    Notes :

    • (?-is) represents two in-line modifiers :

      • -i means that the search is processed with respect to letters case

      • -s means that the dot meta-character, ., represents a single standard character ( not an EOL char ! )

    • The \R, roughly, stands for any kind of line-break ( \r\n with Windows, \n with Unix and \r with Mac )

    • So, the part ^TBA - TO BE ASSIGNED\R looks for the literal line TBA - TO BE ASSIGNED, followed with its like-break

    • Then the part .+(\R|\Z) match any non-null line, with its line-break, as well as a possible line, only followed with line-breaks, before the very end of the document. ( Note that the \Z assertion represents any number, even 0, of consecutive line-break characters, before the very end of current file )

    • And, as this part is embedded in the syntax (.....){2}, this line must occur twice

    • As the replacement zone is EMPTY, this means that these specific 3-lines blocks of text are simply deleted

    Best Regards,

    guy038



  • Meta Chuh, Guy038 etc.
    Many thanks indeed for your help and instructions. The first reply by Meta Chuh was exactly what I was looking for. I needed to add this expression to my existing set of macros to my shortcuts file and Guy’s explanation was much appreciated also.
    Terry


Log in to reply