On 06-Sep-11 12:35:57, 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.
-- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450 Registered in England (0456 0902) 21 Drakes Mews, Milton Keynes, MK8 0ER
sort -n -k 3.4,3.7
does it -- see man sort and the definition of -k POS1[,POS2] and the explanation of POS at the bottom of the man page.
I think your "sort -n -k3.4" only sorts on the first digit!
Ted.
-------------------------------------------------------------------- E-Mail: (Ted Harding) ted.harding@wlandres.net Fax-to-email: +44 (0)870 094 0861 Date: 06-Sep-11 Time: 13:58:37 ------------------------------ XFMail ------------------------------