0

Requirement : I need to write a script to find out for which API the request has been sent but no response received. Given below is an example of the logs i'll be working with.

2014-02-28 12:06:16|information|request|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|response|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|request|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|response|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|***request***|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|request|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|response|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|request|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|response|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|***request***|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|request|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|response|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|request|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293
2014-02-28 12:06:16|information|response|HTTP|API|FROM|TO|240020101281402281736160035001||||78587597|9897968976|23425511000123293

As seen in the ablove logs, In some cases only the request is received but no response. How Can I only print the lines for which response is not received. ????

  • This is difficult to read. It would have been enough to show two lines and state that they are equal except for that field and that no line occurs twice (or, ignoring that field, more than twice). – Hauke Laging Feb 28 '14 at 11:47
  • You really want a unique id to match on, I've had to do something similar and matched on time but as you could imagine, matching is near impossible especially when you get interleaving unless you have a tag/seq# especially over day boundaries. – X Tian Feb 28 '14 at 12:16
1

You replace request and response by the same string so that the lines belonging to each other become equal. Then you search for single lines. If the response line can occur later, too, then you have to sort the lines before this check:

awk -F\| -v OFS=\| '{$3="x";print;}' file | uniq --unique

or

awk -F\| -v OFS=\| '{$3="x";print;}' file | sort | uniq --unique
0

cut can also be your friend

cut -d'|' -f3 will get you that third field, the -f stands for field, starting with 1 on the left (I know, sacrilegious in computers) while the -d is the delimiter that will be used to separate the fields. From there you can pipe it to whatever you would like, if you want the very last line you can pipe it through tail -n1 and so on

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.