Hi,
I am Searching for Multiple strings in a given date range and print the Group if they exists. the below is the format:
[2019/10/16 13:22:47.961][INFO ][ABCDDDDDDD]
-------------------------------------------------------------------------------------------------------------------------
ID: FIRST ID
MESSAGE: Event Message received.
-------------------------------------------------------------------------------------------------------------------------
CONTEXT: {
"ID" : 1,
"event" : "something",
COMMON_TEXT: COMMON
"valid" : true
}
*************************************************************************************************************************
[2019/10/16 13:23:00.816][INFO ][ABCDDDDDEEEEEEE]
-------------------------------------------------------------------------------------------------------------------------
ID: SECOND ID
MESSAGE: Event Message received.
-------------------------------------------------------------------------------------------------------------------------
CONTEXT: {
"ID" : 1,
"event" : "One More thing",
COMMON_TEXT: COMMON
"valid" : true
}
*************************************************************************************************************************
[2019/10/16 13:33:00.816][INFO ][ABCDDDDDEEFFFFFFFFFFFFFEEE]
-------------------------------------------------------------------------------------------------------------------------
ID: THIRD ID
MESSAGE: Event Message received.
-------------------------------------------------------------------------------------------------------------------------
CONTEXT: {
"ID" : 1,
"event" : "Second thing",
COMMON_TEXT: COMMON
"valid" : False
}
*************************************************************************************************************************
SED COMMAND
sed -n '/2019\/10\/23 12:2[0-2]/{:a;N;/2019\/10\/23 12:3[0-3]/!ba; /FIRST ID/p}' logfile
- This is working fine, but I wanted to give one more search criteria along with FIRST ID in the group (like something) and if both exists print the group otherwise skip the group.
AWK Command
awk 'substr($1,2,11)>="2019\/10\/23" && substr($1,2,11)<="2019\/10\/23" && substr($2,1,8)>="12:22:00" && substr($2,1,8)<="12:33:00"' logfile
I am getting only first line with the dates with this group.
I am not a unix expert, can someone please help on this.