I would like to sort an email address list in a file by domain in bash.
$ cat file.txt
abc@abc.net
bbb@aaa.org
aba@aaa.com
aaa@aaa.com
ccc@abb.com
aba@abb.com
abc@abc.com
I tried with sort but it sorts only beginning with the username.
$ sort file.txt
aaa@aaa.com
aba@aaa.com
aba@abb.com
abc@abc.com
abc@abc.net
bbb@aaa.org
ccc@abb.com
I would like to sort first domain then username.
$ sort -t @ -k2 file
aaa@aaa.com
aba@aaa.com
bbb@aaa.org
aba@abb.com
ccc@abb.com
abc@abc.com
abc@abc.net
man sort
:
-t, --field-separator=SEP
use SEP instead of non-blank to blank transition
-k, --key=KEYDEF
sort via a key; KEYDEF gives location and type