occurences or comparison with a list
-
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
-
@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.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.
-
@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 -
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
andWrap 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
-
-
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
-
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
-
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 leadingspace
and/ortabulation
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 theip_address
, which ends each current line, choose the following regex :(?-si)^.+\x20\K(.+)$(?=(?s:.*?^\1$))
Best Regards,
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 -
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 fileAs 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 !
Thanks for your time to collect these infos !
Best Regards,
guy038
-