I have a huge file with some process´s log. The log have lines like "REQUEST (always)/RESPONSE (sometimes)" but RESPONSE is not necessarily the next line after REQUEST. The REQUEST header may occur several times before a RESPONSE if it occurs. I would like to join the REQUEST and RESPONSE (if exists) and then print the line. This is what I tried so far but the output is missing some lines:
awk 'BEGIN {filename = "log1.etb"}
{line_num++; print "FNR: " FNR " NR: " NR " Counter: " line_num;
if ($0 ~ /REQUEST.*RPCLIB/)
{seqid = $0; sub(/^.*@SeqID/,"SeqID",seqid);
line_req = $0; line_resp = ""; ref_resp = 0;
ref_req = line_num; tot_req++;
print "REQUEST: " $0;
for(i=1;i<=line_num+99999;i++1) {getline < "log.etb"; if ($0 ~ /RESPONSE/ && $0 ~ seqid) {ref_resp = +i; line_resp = $0; break;}};
print "FNR: " FNR " NR: " NR " REQUEST: " ref_req " RESPONSE: " ref_resp " " seqid;
print line_req"+"line_resp > filename;
FNR = line_num-1; NR = FNR;
}
}
END {print "Total REQUEST: " tot_req}
' ../EXX/log.etb
Input:
REQUEST 2019-01-16 00:32:07.809@{fields}@SeqID = 9517
RESPONSE 2019-01-16 00:32:07.809@{fields}@SeqID = 9517 , Partner SeqID = 3393
REQUEST 2019-01-16 00:32:07.809@{fields}@SeqID = 9515
REQUEST 2019-01-16 00:32:07.810@{fields}@SeqID = 9520
RESPONSE 2019-01-16 00:32:07.810@{fields}@SeqID = 9520 , Partner SeqID = 3395
Desired output:
REQUEST 2019-01-16 00:32:07.809@{fields}@SeqID = 9517+W02/RESPONSE 2019-01-16 00:32:07.809@{fields}@SeqID = 9517 , Partner SeqID = 3393
REQUEST 2019-01-16 00:32:07.809@{fields}@SeqID = 9515+
REQUEST 2019-01-16 00:32:07.810@{fields}@SeqID = 9520+W02/RESPONSE 2019-01-16 00:32:07.810@{fields}@SeqID = 9520 , Partner SeqID = 3395
SeqID number connects the REQUEST/RESPONSE but it may reoccur in log at some point. Also REQUESTs can occur many times before a RESPONSE and RESPONSE may or may not occur.
SeqID =
that connects a request with a response. Is that correct? Could you maybe mention that in the question?Unique-ID
uniquely identify a request and it's associated response ?