IP Address Sort -numeric -dottedquad

General questions about using TextPad

Moderators: AmigoJack, bbadmin, helios, MudGuard

Post Reply
User avatar
greendragon-mr
Posts: 2
Joined: Tue Feb 27, 2007 4:25 pm

IP Address Sort -numeric -dottedquad

Post by greendragon-mr »

(New to this editor and forum; searched but not found; forgive if duplicate)

I work with IP Addresses, and creating CSV files, etc on a regular basis. I would LOVE to have a sort option for the numeric dotted quad of IP Addresses.

If there is a *simple* way to do this, it should be documented. Otherwise, I'd really appreciate it as a feature request.

Thanks,
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

If all quads have the full three digits, and start in the same column, you can use Block Select mode to select the 15 columns, and then Sort on the selected columns.

If missing all three digits you will need to take the extra steps of loading the missing front zeroes first. I think there is an example of doing that on the forum for Regular Expressions.
Last edited by Bob Hansen on Sat Jun 13, 2009 1:12 am, edited 1 time in total.
Hope this was helpful.............good luck,
Bob
User avatar
greendragon-mr
Posts: 2
Joined: Tue Feb 27, 2007 4:25 pm

Post by greendragon-mr »

Bob Hansen wrote:If all quads have the full three digits, and start in the same column, you can use Block Select mode to select the 15 columns, and then Sort on the selected columns.

If missing all three digits you will need to take the extra steps of loading the missing front zeroes first. I think there is an example of doing that on the fourum for Regular Expressions.
Well, that is a small help -- thank you. However, it would be best to have the ability to sort without munging the address, so if anyone wants to work on that for a future release, it would make me happy! :)
I guess I'll see if I can use this on both ends (my database is without leading zeros), and try to work out that elsewhere.
User avatar
jodell
Posts: 4
Joined: Sat Jul 05, 2008 2:39 pm

Post by jodell »

I too edit/view report and log files that require record sorting on an IP address field. I have done the bit by parsing the address to fixed length fields and sorting but it's objectionably tedious to the point that it's not useful nor is it a complete solution with only one 3 key sort specification. Typical files will have several hundred to 10's of thousands of lines similar to this:

98.21.91.143 2009-05-14 00:37:32 Thu [ 1382] 550
88.205.186.31 2009-05-14 00:58:24 Thu [ 1980] 550
124.120.217.211 2009-05-14 01:47:42 Thu [ 3769] 550
124.120.61.126 2009-05-14 02:23:41 Thu [ 5010] 550
217.25.30.141 2009-05-14 02:24:04 Thu [ 5033] 550
95.83.34.175 2009-05-14 02:28:47 Thu [ 5220] 550
189.106.160.108 2009-05-14 02:34:44 Thu [ 5447] 550

with the IP addresses aligned to the same column. The most useful sort that gives some semblance of order is to sort with KEY 1 = 1-3 numeric with KEY 2 = 1-<END> alpha.

I would be MOST grateful to find that the next update to my beloved TextPad had a native IP (IPv4 dotted quad) sort!! I haven't been faced with IPv6 yet, but suggest that if this feature is added that IPv6 be accommodated also. (i.e. 2001:db8:85a3:0:0:8a2e:370:7334)

It goes without saying that a beta testing contribution on my part would be coveted..

Thanks for listening :)
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

98.21.91.143 2009-05-14 00:37:32 Thu [ 1382] 550
88.205.186.31 2009-05-14 00:58:24 Thu [ 1980] 550
124.120.217.211 2009-05-14 01:47:42 Thu [ 3769] 550
124.120.61.126 2009-05-14 02:23:41 Thu [ 5010] 550
217.25.30.141 2009-05-14 02:24:04 Thu [ 5033] 550
95.83.34.175 2009-05-14 02:28:47 Thu [ 5220] 550
189.106.160.108 2009-05-14 02:34:44 Thu [ 5447] 550


This sample can easily be done with RegEx to fill in the missing zeros.

Find: ^([0-9]*\.[0-9]*\.[0-9]*\.)([0-9]{1}_)
Replace with: \100\2

Find: ^([0-9]*\.[0-9]*\.[0-9]*\.)([0-9]{2}_)
Replace with: \10\2

Note that the "_" is being used to represent the space character

Those two Find/Replace lines will fill in the zeros in the 4th block of the IP. Make similar lines to load the zeros in group 3, then group 2, then the first group.

Similar lines can be made for the first three groups, with each new group search just dropping the first leading "[0-9]*\." from the Find expression. This will result in 8 Find/Replace lines. All eight replacements can be combined into one macro and be accomplished with a single mouse click or a hot key.....
Now the list can be sorted normally, and that sort command could also be included in the macro.

Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
Hope this was helpful.............good luck,
Bob
User avatar
jodell
Posts: 4
Joined: Sat Jul 05, 2008 2:39 pm

Post by jodell »

> This sample can easily be done with RegEx to fill in the missing zeros.

Thanks, Bob.. I have used this and it does work, but it's so tedious to use for frequent heavy use that it isn't practical.

I'm hopeful that a built-in solution is in the pipeline!

Is this scheduled for incorporation any time soon? :)
User avatar
Bob Hansen
Posts: 1516
Joined: Sun Mar 02, 2003 8:15 pm
Location: Salem, NH
Contact:

Post by Bob Hansen »

Make it into a macro. Then you can just click to run the macro. Not tedious at all.
Hope this was helpful.............good luck,
Bob
User avatar
jodell
Posts: 4
Joined: Sat Jul 05, 2008 2:39 pm

Post by jodell »

While Bob's solution worked, I found it to be difficult to use for the things that I was doing. I found another solution that I find easy and flexible.

Creating a "tool" using the GnuWin32 binutils sort command as described in http://www.madboa.com/geek/sort-addr/ really works well for my purposes.

The GnuWin32 utilities can be found at http://gnuwin32.sourceforge.net/packages.html

Tool Settings:

Code: Select all

Command: [C:\Program Files\GnuWin32\bin\sort.exe]
Parameters: [-n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 $File]

[x] Capture output
[x] Suppress output until completed

With one Ctrl-[#] keypress, the file in the current window was IP sorted and output to a "Tool Output" window where the output could be examined. Obviously other techniques could be implemented to suit.
Bob Hansen wrote:
98.21.91.143 2009-05-14 00:37:32 Thu [ 1382] 550
88.205.186.31 2009-05-14 00:58:24 Thu [ 1980] 550
124.120.217.211 2009-05-14 01:47:42 Thu [ 3769] 550
124.120.61.126 2009-05-14 02:23:41 Thu [ 5010] 550
217.25.30.141 2009-05-14 02:24:04 Thu [ 5033] 550
95.83.34.175 2009-05-14 02:28:47 Thu [ 5220] 550
189.106.160.108 2009-05-14 02:34:44 Thu [ 5447] 550


This sample can easily be done with RegEx to fill in the missing zeros.

Find: ^([0-9]*\.[0-9]*\.[0-9]*\.)([0-9]{1}_)
Replace with: \100\2

Find: ^([0-9]*\.[0-9]*\.[0-9]*\.)([0-9]{2}_)
Replace with: \10\2

Note that the "_" is being used to represent the space character

Those two Find/Replace lines will fill in the zeros in the 4th block of the IP. Make similar lines to load the zeros in group 3, then group 2, then the first group.

Similar lines can be made for the first three groups, with each new group search just dropping the first leading "[0-9]*\." from the Find expression. This will result in 8 Find/Replace lines. All eight replacements can be combined into one macro and be accomplished with a single mouse click or a hot key.....
Now the list can be sorted normally, and that sort command could also be included in the macro.

Use the following settings:
-----------------------------------------
[X] Regular expression
Replace All
-----------------------------------------
Configure | Preferences | Editor
[X] Use POSIX regular expression syntax
-----------------------------------------
User avatar
jodell
Posts: 4
Joined: Sat Jul 05, 2008 2:39 pm

Post by jodell »

I should have mentioned that sort is in the CoreUtils package..
jodell wrote:Creating a "tool" using the GnuWin32 binutils sort command as described in http://www.madboa.com/geek/sort-addr/ really works well for my purposes.

The GnuWin32 utilities can be found at http://gnuwin32.sourceforge.net/packages.html
[/quote]
Post Reply