On 06-Sep-11 16:06:56, Mark Rogers wrote:
On 06/09/11 16:54, nev young wrote:
sort --key=3.4 -b -n
Perfect, thanks!
-- Mark Rogers // More Solutions Ltd (Peterborough Office) // 0844 251 1450
Interesting! The key (pun intended) to the problem lies in the separator. Nev's "-b" (accpording to 'man sort') has the effect that: -b, --ignore-leading-blanks ignore leading blanks and the separator option: -t, --field-separator=SEP use SEP instead of non-blank to blank transition So, in your typical input line: 20110905-000108 761 cmd1854 - Command: the default separator occurs at the places indicated below by "|": 20110905-000108| 761| cmd1854| -| Command: and the blanks after each "|" are part of the following field. so that the 3rd field is " cmd1854". Hence the start of the numeric part is at position 5, not position 4. The leading " " in each field is eliminated by "-b". Test (using my test file with an extra 3-digit line): sort --key=3.5 -n < temp.txt ` 20110905-000313 761 cmd858 - Command: 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 766 cmd1854 - Response: 201 Service ready 20110905-000108 803 cmd1854 - Host:/127.0.0.1 opened command interface from port: 57052 20110905-000113 804 cmd1854 - Host:/127.0.0.1 closed command interface from port: 57052 20110905-000313 766 cmd1856 - Response: 201 Service ready 20110905-000313 761 cmd1858 - Command: 20110905-000313 766 cmd1858 - Response: 201 Service ready which is perfect, and also explains why your "-k3.4" did not work! Well well well! Another way to do it, of course, would be sort -t " " --key=3.4 -n < temp.txt Ted. -------------------------------------------------------------------- E-Mail: (Ted Harding) <ted.harding@wlandres.net> Fax-to-email: +44 (0)870 094 0861 Date: 06-Sep-11 Time: 18:58:37 ------------------------------ XFMail ------------------------------