• Login
Community
  • Login

Find a line and copy the next 10 lines

Scheduled Pinned Locked Moved Help wanted · · · – – – · · ·
16 Posts 3 Posters 4.2k 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.
  • M
    Muthuraj Madasamy
    last edited by Dec 4, 2021, 3:55 AM

    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.

    N 1 Reply Last reply Dec 4, 2021, 4:13 AM Reply Quote 0
    • N
      Neil Schipper @Muthuraj Madasamy
      last edited by Dec 4, 2021, 4:13 AM

      @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.

      M 1 Reply Last reply Dec 4, 2021, 4:41 AM Reply Quote 1
      • M
        Muthuraj Madasamy @Neil Schipper
        last edited by Dec 4, 2021, 4:41 AM

        @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

        N 2 Replies Last reply Dec 4, 2021, 4:53 AM Reply Quote 0
        • N
          Neil Schipper @Muthuraj Madasamy
          last edited by Dec 4, 2021, 4:53 AM

          @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.

          M 2 Replies Last reply Dec 4, 2021, 6:11 AM Reply Quote 1
          • M
            Muthuraj Madasamy @Neil Schipper
            last edited by Muthuraj Madasamy Dec 4, 2021, 6:13 AM Dec 4, 2021, 6:11 AM

            This post is deleted!
            1 Reply Last reply Reply Quote 0
            • M
              Muthuraj Madasamy @Neil Schipper
              last edited by Dec 4, 2021, 6:17 AM

              @neil-schipper

              This is the output after

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

              N 1 Reply Last reply Dec 4, 2021, 6:25 AM Reply Quote 0
              • N
                Neil Schipper @Muthuraj Madasamy
                last edited by Dec 4, 2021, 6:25 AM

                @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?

                M 1 Reply Last reply Dec 4, 2021, 7:23 AM Reply Quote 0
                • N
                  Neil Schipper @Muthuraj Madasamy
                  last edited by Neil Schipper Dec 4, 2021, 6:59 AM Dec 4, 2021, 6:58 AM

                  @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.

                  M 1 Reply Last reply Dec 4, 2021, 7:20 AM Reply Quote 0
                  • M
                    Muthuraj Madasamy @Neil Schipper
                    last edited by Dec 4, 2021, 7:20 AM

                    @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++.

                    N 1 Reply Last reply Dec 4, 2021, 7:48 AM Reply Quote 0
                    • M
                      Muthuraj Madasamy @Neil Schipper
                      last edited by Muthuraj Madasamy Dec 4, 2021, 7:24 AM Dec 4, 2021, 7:23 AM

                      @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
                      • N
                        Neil Schipper @Muthuraj Madasamy
                        last edited by Dec 4, 2021, 7:48 AM

                        @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.

                        M 1 Reply Last reply Dec 4, 2021, 8:19 AM Reply Quote 0
                        • M
                          Muthuraj Madasamy @Neil Schipper
                          last edited by Dec 4, 2021, 8:19 AM

                          @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.

                          N 1 Reply Last reply Dec 4, 2021, 8:23 AM Reply Quote 0
                          • N
                            Neil Schipper @Muthuraj Madasamy
                            last edited by Dec 4, 2021, 8:23 AM

                            @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/

                            A 1 Reply Last reply Dec 4, 2021, 12:22 PM Reply Quote 1
                            • A
                              Alan Kilborn @Neil Schipper
                              last edited by Alan Kilborn Dec 4, 2021, 12:23 PM Dec 4, 2021, 12:22 PM

                              @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
                              12 out of 16
                              • First post
                                12/16
                                Last post
                              The Community of users of the Notepad++ text editor.
                              Powered by NodeBB | Contributors