this appears to work on my setup. sort --key=3.4 -b -n < log produced this (from a slightly modified logfile). 20110905-000313 761 cmd9 - Command: 20110905-000113 804 cmd10 - Host:/127.0.0.1 closed command interface from port: 57052 20110905-000108 766 cmd185 - Response: 201 Service ready 20110905-000107 803 cmd1853 - Host:/127.0.0.1 opened command interface from port: 54365 20110905-000108 766 cmd1853 - Response: 201 Service ready 20110905-000108 804 cmd1853 - Host:/127.0.0.1 closed command interface from port: 54365 20110905-000108 761 cmd1854 - Command: 20110905-000108 803 cmx1854 - Host:/127.0.0.1 opened command interface from port: 57052 20110905-000313 766 cmd1856 - Response: 201 Service ready 20110905-000313 766 cmd1858 - Response: 201 Service ready -- nev On 06/09/11 13:35, Mark Rogers wrote:
I have a log file which looks like this: 20110905-000107 803 cmd1853 - Host:/127.0.0.1 opened command interface from port: 54365 20110905-000108 761 cmd1854 - Command: 20110905-000108 766 cmd1853 - Response: 201 Service ready 20110905-000108 766 cmd1854 - Response: 201 Service ready 20110905-000108 803 cmd1854 - Host:/127.0.0.1 opened command interface from port: 57052 20110905-000108 804 cmd1853 - Host:/127.0.0.1 closed command interface from port: 54365 20110905-000113 804 cmd1854 - Host:/127.0.0.1 closed command interface from port: 57052 20110905-000313 761 cmd1858 - Command: 20110905-000313 766 cmd1856 - Response: 201 Service ready 20110905-000313 766 cmd1858 - Response: 201 Service ready
I want to sort it in numeric order on the cmd value. Note that the cmd number isn't always 4 digits and I want cmd9 to appear before cmd10, etc.
Can I do this with sort?
I've seen examples that suggest that something along the lines of sort -n -k3.4 .. would do it but I can't get it working in any of the various permutations I've tried.