Home > linux > sort | About

If your separator is the blank space

use the -k switch, like this :

Without sort :

ychaouche@ychaouche-PC ~/SRV/10.10.10.19/var/log $ sed -n '/Feb 23 13:56/,/Feb 23 14:00/p' mail.log | python mailparser.py
Feb 23 13:56:17 smtpd    11DD1148834F sasl_username=a.chaouche@algerian-radio.dz
Feb 23 13:56:17 cleanup  11DD1148834F message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:17 qmgr     11DD1148834F from=<a.chaouche@algerian-radio.dz> nrcpt=1
Feb 23 13:56:19 pickup   C39951488360 from=<a.chaouche@algerian-radio.dz>
Feb 23 13:56:19 pipe     11DD1148834F to=<m.boulkaboul@algerian-radio.dz> status=sent (delivered via spamassassin service)
Feb 23 13:56:19 qmgr     11DD1148834F removed
Feb 23 13:56:19 cleanup  C39951488360 message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:19 qmgr     C39951488360 from=<a.chaouche@algerian-radio.dz> nrcpt=1
Feb 23 13:56:22 cleanup  3BF90148834F message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:22 qmgr     3BF90148834F from=<a.chaouche@algerian-radio.dz> nrcpt=1
Feb 23 13:56:22 smtp     C39951488360 to=<m.boulkaboul@algerian-radio.dz> queued as 3BF90148834F
Feb 23 13:56:22 qmgr     C39951488360 removed
Feb 23 13:56:22 pickup   725931488360 from=<>
Feb 23 13:56:22 cleanup  725931488360 message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:22 pipe     3BF90148834F to=<m.boulkaboul@algerian-radio.dz> status=sent (delivered via maildrop service)
Feb 23 13:56:22 qmgr     3BF90148834F removed
Feb 23 13:56:22 cleanup  8A814148834F message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:22 smtp     725931488360 to=<n.oumokrane@algerian-radio.dz> queued as 8A814148834F
Feb 23 13:56:22 qmgr     725931488360 removed
Feb 23 13:56:22 pipe     8A814148834F to=<n.oumokrane@algerian-radio.dz> status=sent (delivered via maildrop service)
Feb 23 13:56:22 qmgr     8A814148834F removed
ychaouche@ychaouche-PC ~/SRV/10.10.10.19/var/log $

With sort on the queue ID (5th column) :

ychaouche@ychaouche-PC ~/SRV/10.10.10.19/var/log $ sed -n '/Feb 23 13:56/,/Feb 23 14:00/p' mail.log | python mailparser.py | sort -k5
Feb 23 13:56:17 qmgr     11DD1148834F from=<a.chaouche@algerian-radio.dz> nrcpt=1
Feb 23 13:56:17 cleanup  11DD1148834F message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:19 qmgr     11DD1148834F removed
Feb 23 13:56:17 smtpd    11DD1148834F sasl_username=a.chaouche@algerian-radio.dz
Feb 23 13:56:19 pipe     11DD1148834F to=<m.boulkaboul@algerian-radio.dz> status=sent (delivered via spamassassin service)
Feb 23 13:56:22 qmgr     3BF90148834F from=<a.chaouche@algerian-radio.dz> nrcpt=1
Feb 23 13:56:22 cleanup  3BF90148834F message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:22 qmgr     3BF90148834F removed
Feb 23 13:56:22 pipe     3BF90148834F to=<m.boulkaboul@algerian-radio.dz> status=sent (delivered via maildrop service)
Feb 23 13:56:22 pickup   725931488360 from=<>
Feb 23 13:56:22 cleanup  725931488360 message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:22 qmgr     725931488360 removed
Feb 23 13:56:22 smtp     725931488360 to=<n.oumokrane@algerian-radio.dz> queued as 8A814148834F
Feb 23 13:56:22 cleanup  8A814148834F message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:22 qmgr     8A814148834F removed
Feb 23 13:56:22 pipe     8A814148834F to=<n.oumokrane@algerian-radio.dz> status=sent (delivered via maildrop service)
Feb 23 13:56:19 pickup   C39951488360 from=<a.chaouche@algerian-radio.dz>
Feb 23 13:56:19 qmgr     C39951488360 from=<a.chaouche@algerian-radio.dz> nrcpt=1
Feb 23 13:56:19 cleanup  C39951488360 message-id=<095d7a71694a60e9c0f2191bb6259cf8@algerian-radio.dz>
Feb 23 13:56:22 qmgr     C39951488360 removed
Feb 23 13:56:22 smtp     C39951488360 to=<m.boulkaboul@algerian-radio.dz> queued as 3BF90148834F
ychaouche@ychaouche-PC ~/SRV/10.10.10.19/var/log $ 

If you have other separator

use -t <sep> along with -k.


contact : @ychaouche yacinechaouche at yahoocom


QR Code
QR Code If your separator is the blank space (generated for current page)