Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/sorting/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Unix 如何按日期iso8601对日志文件进行排序?_Unix_Sorting_Logging_Command Line - Fatal编程技术网

Unix 如何按日期iso8601对日志文件进行排序?

Unix 如何按日期iso8601对日志文件进行排序?,unix,sorting,logging,command-line,Unix,Sorting,Logging,Command Line,我的日志不按日期排序: 1. 2013-09-13T09:44:10.581-0400 - 4mainthreadtest@test.com - (v1.6.88) - REPLAY >> Scheduling replay in 2 seconds 2. 2013-09-13T09:44:10.546-0400 - 4mainthreadtest@test.com - (v1.6.88) - REPLAY >> Delay of 106803.116188 s

我的日志不按日期排序:

 1. 2013-09-13T09:44:10.581-0400 - 4mainthreadtest@test.com - (v1.6.88) - REPLAY >>  Scheduling replay in 2 seconds  
 2. 2013-09-13T09:44:10.546-0400 - 4mainthreadtest@test.com - (v1.6.88) - REPLAY >> Delay of 106803.116188 seconds  
 3. 2013-09-13T09:44:10.581-0400 - 4mainthreadtest@test.com - (v1.6.88) - REPLAY >> Hexoskin - replay completed  2013-09-13T09:44:10.535-0400 - 4mainthreadtest@test.com - (v1.6.88) - Hexoskin SDK - Playback ended with  0x0000
我怎样才能订购


我查看了命令行排序,但无法按日期iso8601排序。

您希望按第二个字段(2013-09-13…)排序,而不是整行。可以使用-k参数指定:

sort -k 2 log.txt

只要它们都在同一时区,您就应该能够按字母顺序排列它们。