I need to match 2 patterns consecutively and display 25 lines after that.
1st one - Error
2nd one - End string ( comes along with the pattern one)
3rd one - error
Logic
grep "ERROR OCCURRED :" trace.log | awk -v "ES=:" -v "SS=java.lang.NullPointerException" '{
if($NF ~ ES)
{
print "Inside the if loop";
getline a;
if (a ~ SS) { # here i need to print 25 lines and exit}
}
else
{
if ($0 ~ SS) {# here i need to print 25 lines and exit}
}
}'
I found some code from the net and modified a little bit. But it's printing the line from java.lang.NullPointerException not the first line. I'm exhausted now could you please help.
Input code type 1 ( where ERROR OCCURRED : is in the first line java.lang.NullPointerException second line and the ":" is end string
8581 c3be8 NoUser MST-AP: 01/08/2014 16:34:39 ERROR OCCURRED :
java.lang.NullPointerException
at XXXX
at XXXXX
at XXXX
at XXXX
at XXXX
at XXXX
at XXXX
at XXXX
Input code type 2 ( ERROR OCCURRED : is in the first line java.lang.NullPointerException second line and the ":" is not end string)
1669 9af91 NoUser MST-AP: 01/08/2014 08:54:12 ERROR OCCURRED : Exception:No search List found for user Id
java.lang.NullPointerException
at XXXX
at XXXXX
at XXXX
at XXXX
at XXXX
at XXXX
at XXXX
at XXXX
Your thread title says you want to match two patterns, but your description says you want to match three patterns???
What does "match 3 patterns consecutively" mean?
Find ERROR OCCURRED : somewhere on any line, find a colon character on any line after that, and find SS=java.lang.NullPointerException on any line after that, or
find ERROR OCCURRED : somewhere on any line, find a colon character on the next line, and find SS=java.lang.NullPointerException on the next line, or
something else (and in this case please clearly describe what you want to match)?
And, your initial problem statement says you want to display 25 lines after the match, but later you say you found code but it isn't printing the pattern.
So:
do you want to print the 25 lines immediately following the third match,
the three matched lines and the 25 lines immediately following the third match, or
the first matched line and all lines following it up to and including the line that contained the third match plus the 25 lines immediately following the third match?
It would be a lot easier to help you if you would show us a sample input file and the output you are trying to extract from that sample input in addition to the code that you've tried to use but isn't producing the output you want.
Sorry Don, I explained above and corrected a few things below
Do you want to print the 25 lines immediately following the third match,
Yes, There is no 3 matches, only two, but we will have to different inputs
The three matched lines and the 25 lines immediately following the third match, or
Yes
the first matched line and all lines following it up to and including the line that contained the third match plus the 25 lines immediately following the third match? No
Printing sth from your input samples that would fit what you requested seems not too difficult to me, but that might not fulfill the more general request. To avoid a "doesn't work" comment the very moment some proposal is posted, please show us
some input lines that should be EXCLUDED
which colon (end string, 2. match) in your input files is meant
8581 c3be8 NoUser MST-AP: 01/13/2014 15:20:01 Bill Details from Response
8581 c3be8 NoUser MST-AP: 01/13/2014 15:20:01 Local Currency
8581 c3be8 NoUser MST-AP: 01/13/2014 15:20:01 Successfully got Statement
8581 c3be8 NoUser MST-AP: 01/13/2014 15:20:01 Statement Info exit
8581 c3be8 NoUser MST-AP: 01/13/2014 15:20:01 Provider.send entry
8581 c3be8 NoUser MST-AP: 01/13/2014 15:20:01 Before Sending the Message
8581 c3be8 NoUser MST-AP: 01/13/2014 15:20:01 After Sending the Message
8581 c3be8 NoUser MST-AP: 01/13/2014 15:20:01 Message exit
which colon (end string, 2. match) in your input files is meant
Some time in the logs the ERROR OCCURRED : will come in the last and there wont be any further columns, but some time there is some message comes after that.