I have been trying to sort the output of ipset list into IP
I do
ipset list sshdeny|sort -t. -n -k1,3
Here is an example of the output
5.199.130.188 timeout 1320573
5.2.188.23 timeout 1320572
5.2.72.101 timeout 1320572
5.2.72.110 timeout 1320572
5.2.72.113 timeout 1320572
5.2.77.146 timeout 1320572
5.2.77.22 timeout 1320573
5.2.77.63 timeout 1320573
While the first octet are sorted into numerical order, the second and
third are not. As a number 2 is less than 199. 188 is greater than 72.
On Sat, 24 Oct 2020 21:44:42 -0000 (UTC), William Unruh wrote:
I have been trying to sort the output of ipset list into IP
I do
ipset list sshdeny|sort -t. -n -k1,3
Here is an example of the output
5.199.130.188 timeout 1320573
5.2.188.23 timeout 1320572
5.2.72.101 timeout 1320572
5.2.72.110 timeout 1320572
5.2.72.113 timeout 1320572
5.2.77.146 timeout 1320572
5.2.77.22 timeout 1320573
5.2.77.63 timeout 1320573
While the first octet are sorted into numerical order, the second and
third are not. As a number 2 is less than 199. 188 is greater than 72.
For these kinds of sorts, I prefer version sorting
sort --version-sort --key=1 a
5.2.72.101 timeout 1320572
5.2.72.110 timeout 1320572
5.2.72.113 timeout 1320572
5.2.77.22 timeout 1320573
5.2.77.63 timeout 1320573
5.2.77.146 timeout 1320572
5.2.188.23 timeout 1320572
5.199.130.188 timeout 1320573
On Sat, 24 Oct 2020 21:44:42 -0000 (UTC), William Unruh wrote:
I have been trying to sort the output of ipset list into IP
I do
ipset list sshdeny|sort -t. -n -k1,3
Here is an example of the output
5.199.130.188 timeout 1320573
5.2.188.23 timeout 1320572
5.2.72.101 timeout 1320572
5.2.72.110 timeout 1320572
5.2.72.113 timeout 1320572
5.2.77.146 timeout 1320572
5.2.77.22 timeout 1320573
5.2.77.63 timeout 1320573
While the first octet are sorted into numerical order, the second and
third are not. As a number 2 is less than 199. 188 is greater than 72.
For these kinds of sorts, I prefer version sorting
sort --version-sort --key=1 a
5.2.72.101 timeout 1320572
5.2.72.110 timeout 1320572
5.2.72.113 timeout 1320572
5.2.77.22 timeout 1320573
5.2.77.63 timeout 1320573
5.2.77.146 timeout 1320572
5.2.188.23 timeout 1320572
5.199.130.188 timeout 1320573
On Sat, 24 Oct 2020 22:41:20 +0000, William Unruh wrote:
On 2020-10-24, Bit Twister <BitTwister@mouse-potato.com> wrote:
On Sat, 24 Oct 2020 21:44:42 -0000 (UTC), William Unruh wrote:
I have been trying to sort the output of ipset list into IP
I do
ipset list sshdeny|sort -t. -n -k1,3
Here is an example of the output
5.199.130.188 timeout 1320573
5.2.188.23 timeout 1320572
5.2.72.101 timeout 1320572
5.2.72.110 timeout 1320572
5.2.72.113 timeout 1320572
5.2.77.146 timeout 1320572
5.2.77.22 timeout 1320573
5.2.77.63 timeout 1320573
While the first octet are sorted into numerical order, the second and
third are not. As a number 2 is less than 199. 188 is greater than 72.
For these kinds of sorts, I prefer version sorting
Thanks. Yes sort -V -k1,1 works great.
sort --version-sort --key=1 a
5.2.72.101 timeout 1320572
5.2.72.110 timeout 1320572
5.2.72.113 timeout 1320572
5.2.77.22 timeout 1320573
5.2.77.63 timeout 1320573
5.2.77.146 timeout 1320572
5.2.188.23 timeout 1320572
5.199.130.188 timeout 1320573
You still have 5.199.130... at the bottom of the list, rather than
the top.
Use the command sort -t. -g -k1,3 or
sort --version-sort -g --key=1 a
to get 5.199... at the top of the list.
Cheers!
jim b.
I have been trying to sort the output of ipset list into IP I do ipset
list sshdeny|sort -t. -n -k1,3 Here is an example of the output
5.199.130.188 timeout 1320573 5.2.188.23 timeout 1320572 5.2.72.101
timeout 1320572 5.2.72.110 timeout 1320572 5.2.72.113 timeout 1320572 5.2.77.146 timeout 1320572 5.2.77.22 timeout 1320573 5.2.77.63 timeout 1320573
While the first octet are sorted into numerical order, the second and
third are not. As a number 2 is less than 199. 188 is greater than 72.
On 2020-10-25, Jim Beard <jim.beard@verizon.net> wrote:
On Sat, 24 Oct 2020 22:41:20 +0000, William Unruh wrote:
On 2020-10-24, Bit Twister <BitTwister@mouse-potato.com> wrote:
On Sat, 24 Oct 2020 21:44:42 -0000 (UTC), William Unruh wrote:
I have been trying to sort the output of ipset list into IP I do
ipset list sshdeny|sort -t. -n -k1,3 Here is an example of the output
5.199.130.188 timeout 1320573 5.2.188.23 timeout 1320572 5.2.72.101
timeout 1320572 5.2.72.110 timeout 1320572 5.2.72.113 timeout 1320572
5.2.77.146 timeout 1320572 5.2.77.22 timeout 1320573 5.2.77.63
timeout 1320573
While the first octet are sorted into numerical order, the second and
third are not. As a number 2 is less than 199. 188 is greater than
72.
For these kinds of sorts, I prefer version sorting
Thanks. Yes sort -V -k1,1 works great.
sort --version-sort --key=1 a
5.2.72.101 timeout 1320572 5.2.72.110 timeout 1320572 5.2.72.113
timeout 1320572 5.2.77.22 timeout 1320573 5.2.77.63 timeout 1320573
5.2.77.146 timeout 1320572 5.2.188.23 timeout 1320572 5.199.130.188
timeout 1320573
You still have 5.199.130... at the bottom of the list, rather than the
top.
Use the command sort -t. -g -k1,3 or sort --version-sort -g --key=1 a
to get 5.199... at the top of the list.
Why would I want 5.199 at the top of the list? The octet 199 is much
larger than 2 (binary 00000010 vs 11000111) 199 vs 2 would not be
numeric sort, unless you interpreted the period as a decimal point,
which it is not. So, it would probably be best to think about the number
in European convention, where . acts like the american , in a number.
-n -t. -k1,3 would treat the that first . as a decimal, and does not
work for sorting IP numbers. -n -t. -k1,1 -k2,2 -k3,3 does work, but
does not handle the last one properly, since -k4 would include the whole
line (eg "188 timeout 1320573"
I am not at all sure what -g does. What is a "general numeric"?
On Sun, 25 Oct 2020 16:28:00 +0000, William Unruh wrote:
On 2020-10-25, Jim Beard <jim.beard@verizon.net> wrote:
On Sat, 24 Oct 2020 22:41:20 +0000, William Unruh wrote:
On 2020-10-24, Bit Twister <BitTwister@mouse-potato.com> wrote:
On Sat, 24 Oct 2020 21:44:42 -0000 (UTC), William Unruh wrote:
I have been trying to sort the output of ipset list into IP I do
ipset list sshdeny|sort -t. -n -k1,3 Here is an example of the output >>>>> 5.199.130.188 timeout 1320573 5.2.188.23 timeout 1320572 5.2.72.101
timeout 1320572 5.2.72.110 timeout 1320572 5.2.72.113 timeout 1320572 >>>>> 5.2.77.146 timeout 1320572 5.2.77.22 timeout 1320573 5.2.77.63
timeout 1320573
While the first octet are sorted into numerical order, the second and >>>>> third are not. As a number 2 is less than 199. 188 is greater than
72.
For these kinds of sorts, I prefer version sorting
Thanks. Yes sort -V -k1,1 works great.
sort --version-sort --key=1 a
5.2.72.101 timeout 1320572 5.2.72.110 timeout 1320572 5.2.72.113
timeout 1320572 5.2.77.22 timeout 1320573 5.2.77.63 timeout 1320573
5.2.77.146 timeout 1320572 5.2.188.23 timeout 1320572 5.199.130.188
timeout 1320573
You still have 5.199.130... at the bottom of the list, rather than the
top.
Use the command sort -t. -g -k1,3 or sort --version-sort -g --key=1 a
to get 5.199... at the top of the list.
Why would I want 5.199 at the top of the list? The octet 199 is much
larger than 2 (binary 00000010 vs 11000111) 199 vs 2 would not be
numeric sort, unless you interpreted the period as a decimal point,
which it is not. So, it would probably be best to think about the number
in European convention, where . acts like the american , in a number.
-n -t. -k1,3 would treat the that first . as a decimal, and does not
work for sorting IP numbers. -n -t. -k1,1 -k2,2 -k3,3 does work, but
does not handle the last one properly, since -k4 would include the whole
line (eg "188 timeout 1320573"
I am not at all sure what -g does. What is a "general numeric"?
I did look at the . - . entries as group entries, with 1* preceding 2*.
Your preference definitely does put 5.2. ahead of 5.199.
I do not have the foggiest idea what the definition of a "general
numeric" is, but it is an alternative to both alpha and numeric,
that once in a while does something I prefer.
Cheers!
jim b.
But -n interprets 7.199 ahead of 7.2 (which I sure do not want since
that is hardly true of IP addresses.)Ie, it interprets the . as a
decimal point. Thus you need something like
-n -t. -k1,1 -k2,2 -k3,3
Ie, each of the terms separated by a . are interpreted as numbers.
-m -t. -k1,3 would interpret the whole of the number 2.199.75.46 timout 79443
as first sorting the whole of 2 199 75 as a number, (not sure what it
does with the blanks)
while -n -t. -k1,1 -k2,2 -k3,3
sorts the first number, 2 first then if that is ambiguous, sorts
according to 199 ane then if those two are ambiguous, according to 75.
-V -k1,3 interprets 2.199.75 as a version number where 75 is the
sub-minor version, 199 is the minor version and 2 is the major version.
Ie, it is the same as -n -t. -k1,1 -k2,2 -k3,3
Cheers!
jim b.
On Mon, 26 Oct 2020 03:34:54 +0000, William Unruh wrote:
or...etc...??But -n interprets 7.199 ahead of 7.2 (which I sure do not want since
that is hardly true of IP addresses.)Ie, it interprets the . as a
decimal point. Thus you need something like
-n -t. -k1,1 -k2,2 -k3,3
Ie, each of the terms separated by a . are interpreted as numbers.
-m -t. -k1,3 would interpret the whole of the number 2.199.75.46 timout
79443
as first sorting the whole of 2 199 75 as a number, (not sure what it
does with the blanks)
while -n -t. -k1,1 -k2,2 -k3,3
sorts the first number, 2 first then if that is ambiguous, sorts
according to 199 ane then if those two are ambiguous, according to 75.
-V -k1,3 interprets 2.199.75 as a version number where 75 is the
sub-minor version, 199 is the minor version and 2 is the major version.
Ie, it is the same as -n -t. -k1,1 -k2,2 -k3,3
what on earth are you guys talking about? is it still Linux ...Mageia
On 2020-10-26, santo <santo@auroville.org.in> wrote:its
On Mon, 26 Oct 2020 03:34:54 +0000, William Unruh wrote:
But -n interprets 7.199 ahead of 7.2 (which I sure do not want since
that is hardly true of IP addresses.)Ie, it interprets the . as a
decimal point. Thus you need something like
-n -t. -k1,1 -k2,2 -k3,3
Ie, each of the terms separated by a . are interpreted as numbers.
-m -t. -k1,3 would interpret the whole of the number 2.199.75.46 timout >>> 79443
as first sorting the whole of 2 199 75 as a number, (not sure what it
does with the blanks)
while -n -t. -k1,1 -k2,2 -k3,3
sorts the first number, 2 first then if that is ambiguous, sorts
according to 199 ane then if those two are ambiguous, according to 75.
-V -k1,3 interprets 2.199.75 as a version number where 75 is the
sub-minor version, 199 is the minor version and 2 is the major version.
Ie, it is the same as -n -t. -k1,1 -k2,2 -k3,3
what on earth are you guys talking about? is it still Linux ...Mageia or...etc...??
Yes, it is Linux. The behaviour of the command "sort" in Linux (a
command in the long list of Unix/Linux commands for sorting a list) , and
various arguments.
In particular:
a) what is the meaning of the -g flag -- which the man page says is generalised number.
b) How does one get the command to order a list of IPv4 addresses into
the right (IPv4) order.
Thus you need something like^
-n -t. -k1,1 -k2,2 -k3,3
Ie, each of the terms separated by a . are interpreted as numbers.
-m -t. -k1,3 would interpret the whole of the number
2.199.75.46 timout 79443
as first sorting the whole of 2 199 75 as a number, (not sure what it
does with the blanks)
while -n -t. -k1,1 -k2,2 -k3,3
sorts the first number, 2 first then if that is ambiguous, sorts
according to 199 ane then if those two are ambiguous, according to 75.
-V -k1,3 interprets 2.199.75 as a version number where 75 is the
sub-minor version, 199 is the minor version and 2 is the major version.
Ie, it is the same as -n -t. -k1,1 -k2,2 -k3,3
On Mon, 26 Oct 2020 03:34:54 -0000 (UTC)Yes.
William Unruh <unruh@invalid.ca> wrote:
Thus you need something like^
-n -t. -k1,1 -k2,2 -k3,3
Ie, each of the terms separated by a . are interpreted as numbers.
-m -t. -k1,3 would interpret the whole of the number
I think you mean -n
2.199.75.46 timout 79443
as first sorting the whole of 2 199 75 as a number, (not sure what it
does with the blanks)
I think it tries to interpret 2.199.75 as a number. https://pubs.opengroup.org/onlinepubs/9699919799/utilities/sort.html :
-t char
Use char as the field separator character; char shall not be
considered to be part of a field (although it can be included
in a sort key).
I.e. , if I'm understanding the above correctly , it won't replace the separator by blanks when doing the comparison . So when using the -n
option , the locale may also play a part because in some locales the
dot is used as thousands separator.
while -n -t. -k1,1 -k2,2 -k3,3
sorts the first number, 2 first then if that is ambiguous, sorts
according to 199 ane then if those two are ambiguous, according to 75.
-V -k1,3 interprets 2.199.75 as a version number where 75 is the
sub-minor version, 199 is the minor version and 2 is the major version.
Ie, it is the same as -n -t. -k1,1 -k2,2 -k3,3
But -n -t. -k1,1 -k2,2 -k3,3 is more portable because -V is not in
the POSIX standard.
By the way , a better group for such questions is comp.unix.shell .
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 296 |
Nodes: | 16 (2 / 14) |
Uptime: | 90:32:26 |
Calls: | 6,658 |
Files: | 12,203 |
Messages: | 5,334,093 |