How to sort output of grep command

I grep a directories logs (sys and dbg) for the strings "in service" or "out of service".

$ grep -e "in service" -e "out of service" *

The output returns both phrases found in the *.DBG  and then followed by that found in *.SYS  logs,  
From each log  the entire output (appears) sorted by the log timestamp from earliest to latest...
in other words I see earliest to latest from DBG log then earliest to latest from SYS log - all appended together as one output.

How can I then sort this output so all results found from (each log) are sorted together by time stamp alone,  Example output is below. (some output removed for brevity)

$ grep -V
grep (GNU grep) 3.0
Packaged by Cygwin (3.0-2)
Copyright (C) 2017 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

1000010.DBG:142 10192017 164728.00001:1.09.00965.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: in service
1000010.DBG:145 10192017 164804.00008:1.09.00974.MAJOR   .ISDN : Service PRI-1-9-1-1 primary datalink state: out of service
1000010.DBG:146 10192017 164912.00001:1.09.00978.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: out of service
1000010.DBG:146 10192017 165043.00001:1.09.00983.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: out of service
1000010.DBG:146 10192017 165213.00001:1.09.00987.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: out of service
1000010.DBG:141 10192017 165244.00002:1.09.00988.MAJOR   .ISDN : Service PRI-1-9-1-1 primary datalink state: in service
1000010.DBG:146 10192017 165343.00001:1.09.00992.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: out of service
1000010.DBG:146 10192017 165513.00001:1.09.00997.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: out of service
1000010.DBG:146 10192017 165626.00001:1.09.01008.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: out of service
1000010.DBG:146 10192017 165643.00001:1.09.01012.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: out of service
1000010.DBG:142 10192017 165729.00002:1.09.01016.MAJOR   .ISDN : Service PRI-1-9-1-26 primary datalink state: in service
1000010.DBG:145 10192017 191204.00001:1.09.01173.MAJOR   .ISDN : Service PRI-1-9-1-1 primary datalink state: out of service
1000010.DBG:141 10192017 191204.00002:1.09.01174.MAJOR   .ISDN : Service PRI-1-9-1-1 primary datalink state: in service
1000010.DBG:145 10192017 201927.00088:1.09.01351.MAJOR   .ISDN : Service PRI-1-9-1-1 primary datalink state: out of service
1000010.DBG:141 10192017 201927.00089:1.09.01352.MAJOR   .ISDN : Service PRI-1-9-1-1 primary datalink state: in service
1000010.DBG:145 10192017 201927.00091:1.09.01353.MAJOR   .ISDN : Service PRI-1-9-1-2 primary datalink state: out of service
1000010.DBG:145 10192017 201927.00092:1.09.01354.MAJOR   .ISDN : Service PRI-1-9-1-3 primary datalink state: out of service
1000010.DBG:145 10192017 201927.00094:1.09.01355.MAJOR   .ISDN : Service PRI-1-9-1-4 primary datalink state: out of service
1000010.DBG:145 10192017 201927.00095:1.09.01356.MAJOR   .ISDN : Service PRI-1-9-1-8 primary datalink state: out of service
1000010.DBG:145 10192017 201928.00001:1.09.01357.MAJOR   .ISDN : Service PRI-1-9-1-9 primary datalink state: out of service
1000010.DBG:141 10192017 201928.00002:1.09.01358.MAJOR   .ISDN : Service PRI-1-9-1-9 primary datalink state: in service
1000010.DBG:146 10192017 201928.00004:1.09.01359.MAJOR   .ISDN : Service PRI-1-9-1-10 primary datalink state: out of service
1000010.DBG:141 10192017 201928.00005:1.09.01360.MAJOR   .ISDN : Service PRI-1-9-1-2 primary datalink state: in service
1000010.DBG:141 10192017 201928.00007:1.09.01361.MAJOR   .ISDN : Service PRI-1-9-1-3 primary datalink state: in service
1000010.DBG:141 10192017 201928.00009:1.09.01362.MAJOR   .ISDN : Service PRI-1-9-1-4 primary datalink state: in service
1000010.DBG:142 10192017 201929.00001:1.09.01363.MAJOR   .ISDN : Service PRI-1-9-1-10 primary datalink state: in service
1000010.DBG:141 10192017 201949.00001:1.09.01366.MAJOR   .ISDN : Service PRI-1-9-1-8 primary datalink state: in service
100001F.SYS:145 10192017 190757.00006:1.09.01188.MAJOR   .ISDN : ISDN Service PRI-1-9-1-1 primary D-channel out of service.
100001F.SYS:164 10192017 190757.00009:1.09.01190.MAJOR   .ISDN : ISDN Service PRI-1-9-1-1 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:141 10192017 191204.00003:1.09.01196.Minor   .ISDN : ISDN Service PRI-1-9-1-1 primary D-channel in service.
100001F.SYS:160 10192017 191206.00002:1.09.01197.Minor   .ISDN : ISDN Service PRI-1-9-1-1 Interface 0 B-channel in service map 0xfffffe00.
100001F.SYS:165 10192017 200613.00010:1.09.01231.MAJOR   .ISDN : ISDN Service PRI-1-9-1-26 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:146 10192017 200621.00004:1.09.01232.MAJOR   .ISDN : ISDN Service PRI-1-9-1-26 primary D-channel out of service.
100001F.SYS:145 10192017 201833.00009:1.09.01315.MAJOR   .ISDN : ISDN Service PRI-1-9-1-1 primary D-channel out of service.
100001F.SYS:145 10192017 201833.00014:1.09.01316.MAJOR   .ISDN : ISDN Service PRI-1-9-1-2 primary D-channel out of service.
100001F.SYS:145 10192017 201833.00019:1.09.01317.MAJOR   .ISDN : ISDN Service PRI-1-9-1-3 primary D-channel out of service.
100001F.SYS:145 10192017 201833.00024:1.09.01318.MAJOR   .ISDN : ISDN Service PRI-1-9-1-4 primary D-channel out of service.
100001F.SYS:145 10192017 201833.00068:1.09.01319.MAJOR   .ISDN : ISDN Service PRI-1-9-1-8 primary D-channel out of service.
100001F.SYS:145 10192017 201833.00070:1.09.01320.MAJOR   .ISDN : ISDN Service PRI-1-9-1-9 primary D-channel out of service.
100001F.SYS:146 10192017 201833.00071:1.09.01321.MAJOR   .ISDN : ISDN Service PRI-1-9-1-10 primary D-channel out of service.
100001F.SYS:164 10192017 201833.00224:1.09.01339.MAJOR   .ISDN : ISDN Service PRI-1-9-1-1 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:164 10192017 201833.00225:1.09.01340.MAJOR   .ISDN : ISDN Service PRI-1-9-1-2 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:164 10192017 201833.00226:1.09.01341.MAJOR   .ISDN : ISDN Service PRI-1-9-1-3 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:164 10192017 201833.00227:1.09.01342.MAJOR   .ISDN : ISDN Service PRI-1-9-1-4 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:164 10192017 201833.00228:1.09.01343.MAJOR   .ISDN : ISDN Service PRI-1-9-1-8 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:164 10192017 201833.00229:1.09.01344.MAJOR   .ISDN : ISDN Service PRI-1-9-1-9 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:165 10192017 201833.00230:1.09.01345.MAJOR   .ISDN : ISDN Service PRI-1-9-1-10 Interface 0 B-channel out of service map 0xfffffe00.
100001F.SYS:141 10192017 201927.00090:1.09.01615.Minor   .ISDN : ISDN Service PRI-1-9-1-1 primary D-channel in service.
100001F.SYS:141 10192017 201928.00003:1.09.01616.Minor   .ISDN : ISDN Service PRI-1-9-1-9 primary D-channel in service.
100001F.SYS:141 10192017 201928.00006:1.09.01617.Minor   .ISDN : ISDN Service PRI-1-9-1-2 primary D-channel in service.
100001F.SYS:141 10192017 201928.00008:1.09.01618.Minor   .ISDN : ISDN Service PRI-1-9-1-3 primary D-channel in service.
100001F.SYS:141 10192017 201928.00010:1.09.01619.Minor   .ISDN : ISDN Service PRI-1-9-1-4 primary D-channel in service.
100001F.SYS:142 10192017 201929.00002:1.09.01620.Minor   .ISDN : ISDN Service PRI-1-9-1-10 primary D-channel in service.
100001F.SYS:160 10192017 201929.00006:1.09.01622.Minor   .ISDN : ISDN Service PRI-1-9-1-1 Interface 0 B-channel in service map 0xfffffe00.
100001F.SYS:160 10192017 201930.00004:1.09.01623.Minor   .ISDN : ISDN Service PRI-1-9-1-9 Interface 0 B-channel in service map 0xfffffe00.
100001F.SYS:160 10192017 201930.00005:1.09.01624.Minor   .ISDN : ISDN Service PRI-1-9-1-2 Interface 0 B-channel in service map 0xfffffe00.
100001F.SYS:160 10192017 201930.00006:1.09.01625.Minor   .ISDN : ISDN Service PRI-1-9-1-3 Interface 0 B-channel in service map 0xfffffe00.
100001F.SYS:160 10192017 201931.00002:1.09.01626.Minor   .ISDN : ISDN Service PRI-1-9-1-4 Interface 0 B-channel in service map 0xfffffe00.
100001F.SYS:161 10192017 201931.00006:1.09.01627.Minor   .ISDN : ISDN Service PRI-1-9-1-10 Interface 0 B-channel in service map 0xfffffe00.
100001F.SYS:141 10192017 201949.00002:1.09.01646.Minor   .ISDN : ISDN Service PRI-1-9-1-8 primary D-channel in service.

Open in new window

LinkAsked:
Who is Participating?
 
Hugh FraserConsultantCommented:
Assuming both files have the same format and the 3rd space-delimited column is your date field, try:
   $ grep -e "in service" -e "out of service" * | sort -k 3

This sorts by the 3rd column. This is the simplest form of a column sort... there are lots of ways to narrow down the width of a column.
0
 
David FavorLinux/LXD/WordPress/Hosting SavantCommented:
Looks like you're actually running on Windows (Cygwin) so you'd check your version of Cygwin docs for whatever version of sort they ship with their code.

Just sort on a particular field to produce the sort order you're looking for.

Sometimes Cygwin code works a bit differently than normal Linux/UNIX command line tools, so be sure to refer to your docs for how to get sort working correctly.
0
 
Pawan KumarDatabase ExpertCommented:
Pls try like.....

$ grep -e "in service" -e "out of service" * | Sort
0
 
LinkAuthor Commented:
I was hoping someone already knows how to do this on Windows (Cygwin) .

$ grep -e "in service" -e "out of service" * | Sort
 This is similar  to not using "sort" in that fist I see all output from the dbg log followed by that of sys log...however it actually makes the order of timestamps even worse as it appears to sort only the message content and ignores timestamp.
0
 
LinkAuthor Commented:
Perfect solution! Thanks.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.