Community
    • Login

    Finding and deleting a series of lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    15 Posts 5 Posters 4.7k Views
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Alan KilbornA
      Alan Kilborn @James
      last edited by

      @James

      It would be a manual entry type of thing, with the affected places shown in yellow:

      1ae69dc8-ffd0-448f-bf8f-37e399790efd-image.png

      For automation, you’d have to turn to a scripting plugin, I suppose, if Replace in Files (see the Find in Files tab of the above shown window) doesn’t meet your need.

      1 Reply Last reply Reply Quote 1
      • JamesJ
        James
        last edited by

        Now it’s saying there’s no occurances of that command ((?-is)(^.+\R){n}.Expression.\R(?1){m}). I assume it’s because it’s searching for it as a string, not as a command. How would I input the command from the earlier message to do this? Thank you for your help

        Alan KilbornA 2 Replies Last reply Reply Quote 0
        • Alan KilbornA
          Alan Kilborn @James
          last edited by Alan Kilborn

          @James

          it’s saying there’s no occurances of that command ((?-is)(^.+\R){n}.Expression.\R(?1){m}).

          Well, hopefully you understand that this is a formula and not something you would directly input:

          ddc4710f-c4c0-45ea-b302-d868731ecd36-image.png

          This, however, is an application of that formula, and thus could be directly entered into the Find what box:

          (?-is)^(.+\R){1}.*1234.*\R(?1){4}

          1 Reply Last reply Reply Quote 1
          • Alan KilbornA
            Alan Kilborn @James
            last edited by

            @James said in Finding and deleting a series of lines:

            I assume it’s because it’s searching for it as a string, not as a command.

            I’m confused by this part.
            There is no searching by command, there is only searching by string.

            Alan KilbornA 1 Reply Last reply Reply Quote 1
            • JamesJ
              James
              last edited by

              I should’ve phrased that better. When I try inputting that command in the find what section, it seems to be searching for it as a string, rather than as some sort of formula like you said.

              Terry RT 1 Reply Last reply Reply Quote 0
              • Terry RT
                Terry R @James
                last edited by

                @James said in Finding and deleting a series of lines:

                it seems to be searching for it as a string, rather than as some sort of formula like you said.

                This is a regular expression so the search mode MUST be regular expression. That was the 3rd highlight in the image @Alan-Kilborn provided above.

                Terry

                1 Reply Last reply Reply Quote 1
                • Alan KilbornA
                  Alan Kilborn @Alan Kilborn
                  last edited by

                  @Alan-Kilborn said in Finding and deleting a series of lines:

                  There is no searching by command, there is only searching by string.

                  I suppose that statement I made was misleading, as a “regular expression” rather is more like a formula/command than it is like a string. Sorry for any confusion I brought. :-)

                  1 Reply Last reply Reply Quote 1
                  • JamesJ
                    James
                    last edited by

                    Well even when I use the find what section and regular expression options, it seems to be searching for it as a string regardless. 56fe8fb2-fc01-4025-99e4-eebc8649d599-image.png 0e93ee55-9189-472e-9899-ef3d08970ab2-image.png

                    Alan KilbornA PeterJonesP 2 Replies Last reply Reply Quote 1
                    • Alan KilbornA
                      Alan Kilborn @James
                      last edited by

                      @James

                      Hmm. Yea, I see what you mean. I was using the formula to try to find the text “copy” in the N++ license.txt file. Even though I tweaked the formula a bit so that it would ignore case, I was getting no hits.

                      As @guy038 wrote the formula, I’ll let him comment on what might not quite be right there.

                      1 Reply Last reply Reply Quote 1
                      • PeterJonesP
                        PeterJones @James
                        last edited by PeterJones

                        @James ,

                        It works on a single file for me.

                        ea3f2aad-bd2c-4c05-baea-8896d4ca3eac-image.png

                        eight
                        seven
                        six
                        five
                        four
                        three
                        two
                        one
                        1234
                        one
                        two
                        three
                        four
                        five
                        six
                        seven
                        eight
                        nine
                        ten
                        eleven
                        twelve
                        thirteen
                        fourteen
                        fifteen
                        

                        FIND = (?-is)^(.+\R){7}.*1234.*\R(?1){14}

                        Taking @Alan-Kilborn’s example, I see the problem. The (.+\R) assumes there’s at least one character on every line before or after the matching text. The license.txt has blank lines throughout, so there usually aren’t many lines before and after. So change to (.*\R) => FIND = (?i-s)^(.*\R){7}.*copy.*\R(?1){14} (I also changed to (?i-s) so that the copy was case-insensitive, as Alan mentioned.)

                        0dcfda87-bb8f-43e5-b358-64696bcd69e1-image.png

                        So if your real data has any lines that are blank (just newlines), you will need to use .* instead of .+

                        1 Reply Last reply Reply Quote 2
                        • guy038G
                          guy038
                          last edited by guy038

                          Hello @james, @lan-kilborn, @terry-r, @peterjones and All,

                          @james : Thanks to @peterjones, you have the right solution !

                          So, in summary :

                          • To delete some non-empty lines before and/or after a line, containing Expression, with this exact case :

                            • SEARCH (?-is)(^.+\R){n}.*Expression.*\R(?1){m}

                          • To delete some non-empty lines before and/or after a line, containing Expression, whatever its case

                            • SEARCH (?i-s)(^.+\R){n}.*Expression.*\R(?1){m}

                          • To delete some lines, possibly empty, before and/or after a line, containing Expression, with this exact case :

                            • SEARCH (?-is)(^.*\R){n}.*Expression.*\R(?1){m}

                          • To delete some lines, possibly empty, before and/or after a line, containing Expression, whatever its case

                            • SEARCH (?i-s)(^.*\R){n}.*Expression.*\R(?1){m}

                          • where n represents the number of lines before the line containing Expression ( n >= 0 )

                          • and     m represents the number of lines after    the line containing Expression ( m >= 0 )

                          Best Regards,

                          guy038

                          Alan KilbornA 1 Reply Last reply Reply Quote 0
                          • Alan KilbornA
                            Alan Kilborn @guy038
                            last edited by

                            @guy038

                            Actually, what you’ve specified is for finding some… , not deleting some…

                            To delete, we need to specify:

                            • SEARCH (as above)
                            • REPLACE leave this field blank

                            :-)

                            1 Reply Last reply Reply Quote 1
                            • First post
                              Last post
                            The Community of users of the Notepad++ text editor.
                            Powered by NodeBB | Contributors