Is it possible to sort a key field right to left

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Is it possible to sort a key field right to left

Ernie Luzar
I have a file containing a list of host domain names known to contain
viruses.

I want to sort the host names from right to left so they are grouped
together by like host name suffixes.

Is this possible?
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to sort a key field right to left

Tim Daneliuk
On 09/14/2017 10:07 AM, Ernie Luzar wrote:
> I have a file containing a list of host domain names known to contain
> viruses.
>
> I want to sort the host names from right to left so they are grouped
> together by like host name suffixes.
>
> Is this possible?
https://serverfault.com/questions/364330/sort-a-list-of-domain-names-fqdns-starting-from-tld-and-working-left

----------------------------------------------------------------------------
Tim Daneliuk     [hidden email]
PGP Key:         http://www.tundraware.com/PGP/

_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[hidden email]"
Reply | Threaded
Open this post in threaded view
|

Re: Is it possible to sort a key field right to left

Polytropon
In reply to this post by Ernie Luzar
On Thu, 14 Sep 2017 11:07:40 -0400, Ernie Luzar wrote:
> I have a file containing a list of host domain names known to contain
> viruses.
>
> I want to sort the host names from right to left so they are grouped
> together by like host name suffixes.
>
> Is this possible?

Yes, easily, and provided by the OS. The "sort" command can do it.

Example:

        ... | sort -t '.' +2 | ...

Use the -t parameter to define the field separator, and +N to
set the sorting field (+2 means to sort according to the 3rd
field, i. e., +N means "go to the right N fields").

See "man sort" for details.


--
Polytropon
Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...
_______________________________________________
[hidden email] mailing list
https://lists.freebsd.org/mailman/listinfo/freebsd-questions
To unsubscribe, send any mail to "[hidden email]"