Is it possible to sort a key field right to left

Polytropon freebsd at
Thu Sep 14 18:34:40 UTC 2017

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.


	... | 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.

Magdeburg, Germany
Happy FreeBSD user since 4.0
Andra moi ennepe, Mousa, ...

More information about the freebsd-questions mailing list