Question

I am very new to awk and was struggling to find out all the exception within specific time range.

Below is the logs,

[2014-01-26 00:16:54.244][VendorProductFileProcessor-process-1][WARN] [VendorProductFileTranslatorTask:210] Failed to process vendor data: {INTERNALCASHBACKSNAPDEALSPONSOREDPERCENTAGE=#REF!, VENDOR CODE=#REF!, INTERNALCASHBACKENDDATE=#REF!, INTERNALCASHBACKTYPEVALUE=#REF!, EXTERNALCASHBACKSTARTDATE=#REF!, SKU=#REF!, EXTERNALCASHBACKTYPEVALUE=#REF!, EXTERNALCASHBACKENDDATE=#REF!, EXTERNALCASHBACKTYPE=#REF!, EXTERNALCASHBACKSNAPDEALSPONSOREDPERCENTAGE=#REF!, INTERNALCASHBACKSTARTDATE=#REF!, INTERNALCASHBACKTYPE=#REF!}, com.snapdeal.coms.exception.RuntimeErrorException: COMS-1113: Failed to translate attribute : intCashbackTotalValue value: Unparseable number: "#REF!"

Now I am trying to print all the Exception occurred in last 1 hour. I am using below awk command

grep Exception coms-core.log | gawk -F '[' '{ if ($2 ~ \2014-01-26 00:[0-59]:[0-59]\)print $2}'

But I am getting exception while executing it

gawk: { if ($2 ~ \2014-01-26 00:[0-59]:[0-59]\)print $2}
gawk:            ^ backslash not last character on line

Can someone help me out here?

Using below awk script with the help of anubhava's answer,but when i am trying to use minutes range as regex, it is now working.

grep Exception coms-core.log | head -1 | gawk -F '[' ' $2 ~ /^2014-01-26 [00]:[0-59]/ {print $2}'

Was it helpful?

Solution

Try this awk:

gawk -F '[' '$0 ~ /Exception/ && $2 ~ /^2014-01-26 16:/ {print $2}' coms-core.log
  • You don't need grep since awk can handle that part as well
  • Your awk syntax wasn't correct

OTHER TIPS

Regular expressions are denoted with a forward slash (/expr/).

To find out exception in last 1 hour using find command -

find . -maxdepth 1 -mmin -60 -name 'coms-core.log' -exec grep -wi 'exceptions' {} \; 2>/dev/null

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top