Reputation: 43
I would like to sort an email address list in a file by domain in bash.
$ cat file.txt
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
I tried with sort but it sorts only beginning with the username.
$ sort file.txt
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
I would like to sort first domain then username.
Upvotes: 4
Views: 2144
Reputation: 37464
$ sort -t @ -k2 file
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
[email protected]
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
Upvotes: 6