Community
    • Login

    Find a line and copy the next 10 lines

    Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
    16 Posts 3 Posters 2.8k 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.
    • Muthuraj MadasamyM
      Muthuraj Madasamy
      last edited by

      Re: Find a line and copy the next 10 lines

      Can some one explain how to use the line filter for this above task? I need to selecct 10 lines below one common specific lines. I installed the line filter but some one can help me with the process

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

        @muthuraj-madasamy

        I wouldn’t use “line filter” for this.
        There’s a very reasonable way to do specified by @guy038 in the thread you linked to:

        a regex marking operation for ^.*12345.*\R(.*\R){10}

        presuming your spec for “one common specific line” was “a line containing 12345”

        You’d do this Mark All operation:

        f17c12fb-50b0-4fac-b84c-e93befe54c3d-image.png

        Which would highlight the match in red, for example:

        295369a2-491e-4aac-b4d4-2c0226590cd7-image.png

        And then if you Copy Marked Text and paste it somewhere else, you obtain:

                   12345
        To do so, attach the following notices to the program. It is safest to attach them to the start of each source file to most effectively state the exclusion of warranty; and each file should have at least the "copyright" line and a pointer to where the full notice is found.
        
            <one line to give the program's name and a brief idea of what it does.>
            Copyright (C) <year>  <name of author>
        
            This program is free software: you can redistribute it and/or modify
            it under the terms of the GNU General Public License as published by
            the Free Software Foundation, either version 3 of the License, or
            (at your option) any later version.
        
        
        1 Reply Last reply Reply Quote 1
        • Muthuraj MadasamyM
          Muthuraj Madasamy
          last edited by

          Hi Alan
          Thank you very much for spending time on my request.

          I tried for my file, it is not working. It is selecting all the lines.

          I want to search with below lines and copy the 10 lines present below to the lines. Similar blocks are there in multiple location in my log fie.

          common specific line is “show chassis environment pem” and i gave the regex as “^.show chassis environment pem.\R(.*\R){10}”

          It is seclecting all my lines in the log. Few words are common in other lines “show, chassis, environment”.

          I tried with only PEM as that is the unique as “^.* pem|.\R(.\R){10}” but not achieving the required one.

          Let me know if i miss anything here.

          Neil SchipperN 1 Reply Last reply Reply Quote 0
          • Neil SchipperN
            Neil Schipper @Muthuraj Madasamy
            last edited by

            @muthuraj-madasamy Your first example has missing asterisks * and your second has an or bar | that is not part of Alan’s solution.

            Regex machinery cares very little for your intentions, and demands rigid compliance to correct syntax.

            I suggest you copy his text, paste, and then carefully replace just the 5 characters 12345 with text you want.

            Muthuraj MadasamyM 1 Reply Last reply Reply Quote 1
            • Muthuraj MadasamyM
              Muthuraj Madasamy @Neil Schipper
              last edited by

              @neil-schipper
              Thank you and belwo is the output. This is a huge log file.

              ^.pem.\R(.*\R){10}

              I used above search but still not selecting all the lines. As you see in the below image.

              7089948e-05e7-4028-82d6-d97211cc1e77-image.png

              Neil SchipperN 2 Replies Last reply Reply Quote 0
              • Neil SchipperN
                Neil Schipper @Muthuraj Madasamy
                last edited by

                @muthuraj-madasamy Hi.
                First, remove the check from . matches newline like in the image Alan provided.

                Second, I see you used ^.pem.\R(.*\R){10}. Again, this wrong. What you need is ^.*pem.*\R(.*\R){10}. The dot . and asterisk * characters have special meaning to the software that performs regular expression processing; you cannot add/remove them casually.

                Muthuraj MadasamyM 2 Replies Last reply Reply Quote 1
                • Muthuraj MadasamyM
                  Muthuraj Madasamy @Neil Schipper
                  last edited by Muthuraj Madasamy

                  This post is deleted!
                  1 Reply Last reply Reply Quote 0
                  • Muthuraj MadasamyM
                    Muthuraj Madasamy @Neil Schipper
                    last edited by

                    @neil-schipper

                    This is the output after

                    0fcc3186-c9cd-4c6d-a07c-fdd7e8b14fc5-image.png

                    Neil SchipperN 1 Reply Last reply Reply Quote 0
                    • Neil SchipperN
                      Neil Schipper @Muthuraj Madasamy
                      last edited by

                      @muthuraj-madasamy

                      I don’t want to have to shout but you really need to remove the check from . matches newline like in the image Alan provided

                      It’s in the Search Mode box. See it?

                      Muthuraj MadasamyM 1 Reply Last reply Reply Quote 0
                      • Neil SchipperN
                        Neil Schipper @Muthuraj Madasamy
                        last edited by Neil Schipper

                        @muthuraj-madasamy said in Find a line and copy the next 10 lines:

                        ^.pem.\R(.*\R){10}
                        I used above search but still not selecting all the lines. As you see in the below image.

                        Hi. You didn’t notice that the expression that appears above is different from what you typed or pasted in, right? It’s missing two asterisks of the original. This is because when you paste text with asterisks in this discussion board, software converts the text to italics so people can make PRETTY TEXT. (The preview pane let’s you see this, but you have to look carefully.)

                        The way to prevent this is to use one of the two triple backquote techniquesas described in Please Read Before Posting.

                        Well, I didn’t notice either, and I was wrong to suggest you were using the wrong expression.

                        Muthuraj MadasamyM 1 Reply Last reply Reply Quote 0
                        • Muthuraj MadasamyM
                          Muthuraj Madasamy @Neil Schipper
                          last edited by

                          @neil-schipper said in Find a line and copy the next 10 lines:
                          Hi Neil
                          I understood that while responding the search word came default and i didn’t notice that you have taken that as a reference and providing the comments.

                          Can you see the image which i pasted there, in that one i have entered the correct format?

                          Thanks for spending time with me and i am a new user for notepad++.

                          Neil SchipperN 1 Reply Last reply Reply Quote 0
                          • Muthuraj MadasamyM
                            Muthuraj Madasamy @Neil Schipper
                            last edited by Muthuraj Madasamy

                            @neil-schipper

                            Thanks a lot. I got your point. the check point is creating trouble. I am able to make it now

                            2a750a5c-b9c1-48da-b8cb-6189902292a2-image.png

                            once again thanks a lot for helping to fix this

                            1 Reply Last reply Reply Quote 0
                            • Neil SchipperN
                              Neil Schipper @Muthuraj Madasamy
                              last edited by

                              @muthuraj-madasamy said in Find a line and copy the next 10 lines:

                              Can you see the image which i pasted there, in that one i have entered the correct format?

                              Yes, but I noticed it too late. The text in the image is small and I didn’t think to cross-check.

                              @muthuraj-madasamy said in Find a line and copy the next 10 lines:

                              fix this

                              I’m happy to hear it’s working.

                              Muthuraj MadasamyM 1 Reply Last reply Reply Quote 0
                              • Muthuraj MadasamyM
                                Muthuraj Madasamy @Neil Schipper
                                last edited by

                                @neil-schipper

                                Yes Neil…Thanks a lot…

                                Can you help me any tutorial info for using notepad++? I am new user and not much familiar with these operations.

                                Neil SchipperN 1 Reply Last reply Reply Quote 0
                                • Neil SchipperN
                                  Neil Schipper @Muthuraj Madasamy
                                  last edited by

                                  @muthuraj-madasamy said in Find a line and copy the next 10 lines:

                                  any tutorial info for using notepad++

                                  I’m not sure what you are asking for or needing to know, but it is good if you become familiar with these:

                                  https://npp-user-manual.org/docs/preferences
                                  https://npp-user-manual.org/docs/searching/

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

                                    @neil-schipper

                                    Wow, Neil, thanks for dealing with THAT, and sparing me. :-)

                                    @Muthuraj-Madasamy

                                    Additional good reference on regular expressions (the technique shown above to solve the problem) is found starting HERE.

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