Avatar of Link
Link
Flag for United States of America asked on

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

Linux* BashSoftware

Avatar of undefined
Last Comment
Link

8/22/2022 - Mon
David Favor

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.
Pawan Kumar

Pls try like.....

$ grep -e "in service" -e "out of service" * | Sort
Link

ASKER
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.
Experts Exchange is like having an extremely knowledgeable team sitting and waiting for your call. Couldn't do my job half as well as I do without it!
James Murphy
ASKER CERTIFIED SOLUTION
Hugh Fraser

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
Link

ASKER
Perfect solution! Thanks.