Deletion of any line based on above mentioned Two Lines



  • Hi,
    I want to delete line “<readOnly>true</readOnly>” if the above two lines are “<isRetrievable>false</isRetrievable>” and “<idName></idName>”.
    Can any one help me doing this. I am struggling with this as i have to do this for notepad++ file which is having 10000 Lines.

    Any help would be appriciated.

    <par>
    <name>Nitish</name>
    <type>UINT32</type>
    <value>0</value>
    <dataUnit>min</dataUnit>
    <text></text>
    <isRetrievable>false</isRetrievable>
    <idName></idName>
    <readOnly>true</readOnly>
    </par>

      <par>
        <name>Ashish</name>
        <type>INT32</type>
        <value>0x7FFFFFFF</value>
        <dataUnit>CentiCelsius</dataUnit>
        <text></text>
        <isRetrievable>false</isRetrievable>
        <idName></idName>


  • Bit bucket plugin can help you by replace multilines



  • @Nitish-Singh said:

    I want to delete line …

    Taking you at your literal word, that we’re only looking for those literal phrases:

    • FIND = <isRetrievable>false</isRetrievable>\R<idName></idName>\R\K<readOnly>true</readOnly>\R?
      • \R means “newline sequence”
      • \R? means “0 or 1 newline sequences, greedy” (so if there is a newline after the readOnly line, it will be deleted, but if the readOnly line happens to be the last line of the file, with no trailing newline, the readOnly line will still be deleted
      • \K means “the stuff before the \K must be there, but only the stuff after the \K will be replaced”
      • most of that expression is literal
    • REPLACE = (empty)
    • Search mode = Regular Expression

    If you need more variety in the readOnly line (that is, if it’s not always the literal text <readOnly>true</readOnly>, you’ll have to be more specific.

    -----

    Please Read And Understand This

    FYI: I often add this to my response in regex threads, unless I am sure the original poster has seen it before. Here is some helpful information for finding out more about regular expressions, and for formatting posts in this forum (especially quoting data) so that we can fully understand what you’re trying to ask:

    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.



  • Hello, @nitish-singh, @gurikbal-singh, @peterjones and All,

    As some of the lines of the XML file are, likely, preceded by some leading blank characters, the solution, below, should be preferred :

    SEARCH ^\h*<isRetrievable>false</isRetrievable>\R\h*<idName></idName>\R\K\h*<readOnly>true</readOnly>\R?

    REPLACE Leave EMPTY

    Best regards,

    guy038


Log in to reply