Sort in chronological order

I am trying to sort a log file in chronological order to identify which ones did not process and still have an old (probably yesterday's) date. This is a sample of the file:

flatf 010140 flatf Thu May 10 22:22:11 CST 2018  flats finished
flatf 010142 flatf Thu May 10 22:31:25 CST 2018  flats finished
flatf 010148 flatf Thu May 10 22:38:49 CST 2018  flats finished

I am trying to use "-M" to sort the months in order, but a command of

sort + 8 -9 -M +4 +5

doesn't appear to do anything and leaving "-M" out works except the months are in alphabetical order (Apr, Aug, Dec, etc.).
The output would be piped into a head command where the top line(s) may show a problem. What am I missing?

TIA

Assuming that your sort utility has a -M option (which is not required in standard sort utilities), you might want to try the following:

sort -k9,9n -k5,5M -k6,6n -k7,7

to perform a numeric sort on the year, a month sort on the abbreviated month, a numeric sort on the day, and a string sort on the time. This should sort by increased timestamps except during the shift from daylight saving time to standard time where the date sort should be correct, but the timestamp sort within those dates might be wrong for two hours on those days.

2 Likes

When I ran "man sort" I saw the "-M" option but didn't know how to implement it. Works like a charm:

flatf 010156 flatf Thu May 10 22:47:48 CST 2017  flats finished    
flatf 030118 flatf Thu Xxx 10 22:19:47 CST 2018  flats finished    
flatf 010186 flatf Thu Feb 10 22:16:21 CST 2018  flats finished    
flatf 010190 flatf Thu Mar 10 22:38:57 CST 2018  flats finished    
flatf 010165 flatf Thu Apr 10 22:29:21 CST 2018  flats finished    
flatf 010127 flatf Wed May  9 22:16:59 CST 2018  flats finished    
flatf 090938 flatf Thu May 10 22:05:02 CDT 2018  flats finished

Again, many thanks!

How is it that the log file is not already in chronological order.

Those log records are not created locally. If a procedure runs to completion, it over writes that record and the log files (actually one record each) should be sent to us. If the first record of a concatenated sorted log file is about 24 hours or more earlier than the second one, we have a problem.