You are here: PSPad forum > English discussion forum > Re: Sorting IP Addresses

Re: Sorting IP Addresses

#1 Sorting IP Addresses

Posted by: BudMan | Date: 2014-11-15 12:43 | IP: IP Logged

I have a need to sort IP addresses. I can use GNU "sort", but that is not available on an MS Windows machine. Plus, I want to be able to sort the addresses within PSPad. The syntax for GNU Sort is this:

sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 filename.txt

Is there any built in ability to do that with PSPad?

Thanks!

--
BudMan

Options: Reply | Quote | Up ^


#2 Re: Sorting IP Addresses

Posted by: pspad | Date: 2014-11-15 19:17 | IP: IP Logged

I am afraid there is no possibility how to sort it except write your script

Options: Reply | Quote | Up ^


#3 Re: Sorting IP Addresses

Posted by: BudMan | Date: 2014-11-15 19:47 | IP: IP Logged

Okay, well maybe it can be added to the TODO list of possible improvements to PSPad. It is just a suggestion.

--
BudMan

Options: Reply | Quote | Up ^


#4 Re: Sorting IP Addresses

Posted by: pspad | Date: 2014-11-15 19:50 | IP: IP Logged

Why not, if there will be more people who will find it useful.

Options: Reply | Quote | Up ^


#5 Re: Sorting IP Addresses

Posted by: carbonize | Date: 2014-11-15 23:29 | IP: IP Logged

Personally it's something I would write myself in PHP and just use the local PHP executable.

--
Carbonize

Options: Reply | Quote | Up ^


#6 Re: Sorting IP Addresses

Posted by: vbr | Date: 2014-11-16 01:35 | IP: IP Logged

BudMan:
I have a need to sort IP addresses. I can use GNU "sort", but that is not available on an MS Windows machine. Plus, I want to be able to sort the addresses within PSPad. The syntax for GNU Sort is this:

sort -n -t . -k 1,1 -k 2,2 -k 3,3 -k 4,4 filename.txt

Is there any built in ability to do that with PSPad?

Thanks!

Hi,
if you already have a sorting routine for GNU sort, you may be able to use it in windows too, e.g. viy cygwin or UnxUtils and maybe some others
unxutils.sourceforge.net
sourceforge.net

I don't use it myself, but in some short tests, it appears to work as expected, using the sample from
www.madboa.com

(A script addon for PSPad may be doable to, probably one would create a nested list with integers, sort it, and recreate the textual form of the addresses.)
=========
out of curiosity, I just tried to accomplish this with the builtin pspad functionality - it seems possible too, although not really straightforward ...

==========

unsorted ip addresses; cf. www.madboa.com
129.95.30.40
5.24.69.2
19.20.203.5
1.2.3.4
19.20.21.22
5.220.100.50

prepend two spaces to all items (before a "word-break" - after each dot or a line begin) with a regexp replace:
(\b.)
>>replace with>>
$1

129. 95. 30. 40
5. 24. 69. 2
19. 20. 203. 5
1. 2. 3. 4
19. 20. 21. 22
5. 220. 100. 50

align the data - ignore the superfluos starting spaces, keep only 3-char items; regexp replace:
{0,2}([ \d]{3})\b
>>>
$1

129. 95. 30. 40
5. 24. 69. 2
19. 20.203. 5
1. 2. 3. 4
19. 20. 21. 22
5.220.100. 50

edit: sort - ascii:
1. 2. 3. 4
5. 24. 69. 2
5.220.100. 50
19. 20. 21. 22
19. 20.203. 5
129. 95. 30. 40

remove all spaces - regexp
+
>>>
[emptystring]
1.2.3.4
5.24.69.2
5.220.100.50
19.20.21.22
19.20.203.5
129.95.30.40


[edit: the spaces probably aren't displayed well in the post; they can be viewed temporarilly in the edit window after clicking "quote" like to create a follow-up post; of course, this needen't to be really saved in such a case]
=========
hth,
vbr

Edited 3 time(s). Last edit at 2014-11-16 01:43 by vbr.

Options: Reply | Quote | Up ^


#7 Re: Sorting IP Addresses

Posted by: therium | Date: 2015-02-24 12:52 | IP: IP Logged

Hello, there are GNU utils provided for windows. Have you tried the GNU sort for windows? I think these are 2 different packages:

gnuwin32.sourceforge.net

unxutils.sourceforge.net

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2024 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR