I have some mail log excerpts that I'd like to sort first by e-mail address and then by date.
Example input data:
$ cat test3.txt
Oct 10 14:00:00 [email protected] bounced
Oct 10 13:00:00 [email protected] deferred
Oct 10 14:30:00 [email protected] bounced
Oct 10 12:00:00 [email protected] deferred
Oct 9 12:00:00 [email protected] deferred
Oct 9 14:00:00 [email protected] bounced
Oct 10 12:30:00 [email protected] deferred
Oct 10 13:30:00 billy@example.com deferred
Oct 9 13:00:00 [email protected] deferred
The file in its current version is space delimited. So what I want is to sort first by the fourth column, and then by the first (as month), second (numerical) and third (numerical, I guess, unless the timestamps need special handling.) This is my best attempt:
$ sort -k 4,4 -k 1,1M -nk 2 test3.txt
Oct 9 12:00:00 [email protected] deferred
Oct 9 13:00:00 [email protected] deferred
Oct 9 14:00:00 [email protected] bounced
Oct 10 12:00:00 [email protected] deferred
Oct 10 12:30:00 [email protected] deferred
Oct 10 13:00:00 [email protected] deferred
Oct 10 13:30:00 [email protected] deferred
Oct 10 14:00:00 and[email protected] bounced
Oct 10 14:30:00 [email protected] bounced
If I include only the "-k 4,4" key argument, it sorts fine according to the e-mail but that seems to get ignored when I add the other keys. For simplicity the first column can be ignored in this example; the problem is still there in that the sorting by the second column takes precedence over the fourth.
What am I doing wrong?