• Login
Community
  • Login

occurences or comparison with a list

Scheduled Pinned Locked Moved Notepad++ & Plugin Development
9 Posts 4 Posters 2.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.
  • C
    chamzon chamzon
    last edited by Apr 20, 2022, 10:25 PM

    Hello everyone
    I hope I can find a solution to my little problem,

    I have 2 files, a firewall configuration file and another file with an ip address list,
    and I would like to know if the IP’s in the left side appear in the right side conf file.

    I tried with the COMPARE plugin but it does not give me the expected result

    Thanks for you help

    alt text

    L 1 Reply Last reply Apr 20, 2022, 10:54 PM Reply Quote 0
    • L
      Lycan Thrope @chamzon chamzon
      last edited by Apr 20, 2022, 10:54 PM

      @chamzon-chamzon
      That’s not how the Compare Plugin works, it checks two files and shows the differences between them. You have two completely different files, and all that will be highligted is the missing parts. The following sceenshot shows two different files being compared, and all that shows is similar things.

      Acomparefilesexample.PNG

      This plugin is usually used to find the differernce between two files that are similar, like a newer copy of the same document to see the changes that were made, like in program code files.

      C 1 Reply Last reply Apr 20, 2022, 11:03 PM Reply Quote 0
      • C
        chamzon chamzon @Lycan Thrope
        last edited by Apr 20, 2022, 11:03 PM

        @lycan-thrope
        thanks for reply, i use the compare plugin bcause it’s the only one i know, i did find another one matching my need

        1 Reply Last reply Reply Quote 0
        • G
          guy038
          last edited by guy038 Apr 21, 2022, 10:21 PM Apr 21, 2022, 10:29 AM

          Hello, @chamzon-chamzon and All,

          You can easily achieve your goal with a regular expression search !

          Here is the road map :

          • Open a new N++ tab ( Ctrl + N )

          • First, paste the contents of your firewall configuration file ( Ctrl + V )

          • Then, append the contents of your ip-adresses list, right after

          Starting, for instance, with this example text :

          tag RJPROJ
          ip-netmask 192.168.2.4
          tag RJPROJ
          ip-netmask 192.168.2.152
          tag RJPROJ
          ip-netmask 192.168.2.24
          tag RJPROJ
          ip-netmask 192.168.2.25
          tag RJPROJ
          ip-netmask 10.7.18.188
          tag RJPROJ
          ip-netmask 10.7.18.28
          tag RJPROJ
          ip-netmask 10.7.18.29
          tag RJPROJ
          ip-netmask 10.7.18.249
          tag RJPROJ
          ip-netmask 10.7.18.226
          tag RJPROJ
          ip-netmask 10.7.18.12
          tag FJPROJ
          ip-netmask 10.7.18.13
          tag FJPROJ
          ip-netmask 10.7.18.16
          tag FJPROJ
          ip-netmask 10.7.16.2
          10.7.16.2
          10.7.16.5
          10.7.16.6
          10.7.16.7
          10.7.16.8
          10.7.18.11
          10.7.18.16
          10.7.18.17
          10.7.18.18
          10.7.18.22
          10.7.18.226
          10.7.23.1
          10.7.23.66
          10.7.23.45
          10.7.23.44
          10.7.23.26
          10.7.23.156
          10.7.23.16
          10.7.18.188
          
          • Now, open the MARK dialog ( Ctrl + M )

            • SEARCH (?s-i)^ip-netmask\x20\K(.+)$(?=.*?^\1)

            • Un-tick all options

            • Tick the Bookmark line, Purge for each search and Wrap around options

            • Select the Regular expression search mode

            • CLick on the Mark All button => 4 matches !

          • From this point, you can, either :

            • Click on the Copy Marked Text button and paste all the IP-adresses elsewhere

            • Use the menu option Search > Bookmark > Copy Bookmarked Lines and paste all these specific lines elsewhere

          Best Regards,

          guy038

          C 1 Reply Last reply Apr 22, 2022, 12:52 PM Reply Quote 2
          • C
            chamzon chamzon @guy038
            last edited by Apr 22, 2022, 12:52 PM

            @guy038

            Thank you very much Guy038 ! It’s so kind.

            I’m not very familiar with the reghex but I see it’s very powerful !
            In my example, the word “ip-netmask” is not the begining of the line,
            so how can i change this to search any word at the begining ?

            Thank you

            for the moment, it gives me only one (wrong) result

            P 1 Reply Last reply Apr 22, 2022, 2:10 PM Reply Quote 0
            • P
              PeterJones @chamzon chamzon
              last edited by Apr 22, 2022, 2:10 PM

              @chamzon-chamzon ,

              The reason it didn’t work is that your screenshot misrepresented the data. Regex are highly tailored to example data, and when you make us guess, we guess wrong.

              https://community.notepad-plus-plus.org/topic/22022/faq-desk-template-for-search-replace-questions

              1 Reply Last reply Reply Quote 2
              • G
                guy038
                last edited by guy038 Apr 25, 2022, 7:10 AM Apr 22, 2022, 5:31 PM

                Hello, @chamzon-chamzon, @lycan-thrope, @peterjones and All,

                Ah… , OK ! Then, two possibilities :

                • If you want to say that the ip-netmask string may be preceded with possible leading space and/or tabulation characters, choose the following regex :

                  • (?-si)^\h*ip-netmask\x20\K(.+)$(?=(?s:.*?^\1$))
                • If you want to say that any non-null string, may precede the space char and the ip_address, which ends each current line, choose the following regex :

                  • (?-si)^.+\x20\K(.+)$(?=(?s:.*?^\1$))

                Best Regards,

                guy038

                C 1 Reply Last reply Apr 24, 2022, 10:22 PM Reply Quote 2
                • C
                  chamzon chamzon @guy038
                  last edited by Apr 24, 2022, 10:22 PM

                  @guy038

                  Thank you very much ! you’re a boss !
                  It works with the last regex.
                  But is there any limitation ? because it works when I have few lines as config (like 50 lines), but when I use the whole file which has 68000 lines it doesn’t give any result.

                  Thanks again,
                  Kind regards,
                  Chamzon

                  1 Reply Last reply Reply Quote 0
                  • G
                    guy038
                    last edited by guy038 Apr 25, 2022, 7:45 AM Apr 25, 2022, 7:40 AM

                    Hi, @chamzon-chamzon, @lycan-thrope, @peterjones and All,

                    OK… I understand that in real cases, this causes a complete failure of the regex engine :-(( Why ?

                    Well, let’s suppose the temporary file containing, first, your entire firewall configuration file followed with your entire IP-adresses list file

                    Now, imagine the worst case : an unique match between the first IP-address of your firewall configuration file and the last IP-address of your IP-adresses list

                    Then, and despite I use a non-capturing regex group, the part of the regex (?s:.*?...) represents all the characters, included line-endings, right after the first IP-address till the same IP-address excluded, at the very end of file

                    As you said that your firewall configuration file has about 68,000 lines, it’s easy to guess that it probably exceeds the capacity of the regex engine to handle such a gap of chars !!


                    So, in order to find out, somehow, a work-around to this situation, could you give me :

                    • The number of lines of your firewall configuration file and its approximate size

                    • The number of lines of your IP-addreses list and its approximate size

                    • A short example of your real firewall configuration file

                    • A short example of your real IP-addresses list

                    In order to get the raw text, click on that button, when writing your post, to insert text in the right way !

                    41d95003-7608-410a-958d-539e9c906c41-Capture d’écran 2022-03-07 123711.png

                    Thanks for your time to collect these infos !

                    Best Regards,

                    guy038

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