I wanted to grep string "ERROR" and "WORNING" after last occurrence of String "Starting" only and wanted to display two lines after searched ERROR and WORNING string and one line before. I have following cronjob log file "errorlog" file and I have written the code for same in Unix as below and working fine but not able to implement it in SunSolari.
Please find errorlog file as below :
it is Starting
line1
line2
ERROR
line3
line4
it is Starting
line5
ERROR
line6
line7
it is Starting
line8
WARNING
line8.8
line8.9
line9
ERROR
line10
line11
Expected output something like as follow :
line8
WARNING
line8.8
line9
ERROR
line10
Following code is working in UNIX/LINUX but not working in SunSolari
I have given example of file, but not sure how many time "Starting" string is present in file.
I want only from last occurrence of string("Starting")to end of file where file has "ERROR" or "EXCEPTION".
Could you please give me one example of a UNIX/LINUX system where the above sequence of commands produces the expected output you showed us above when given the sample errorlog file you provided above as input?
I would expect the above code to display a subset of the text starting with the 1st line of the file and ending on the line before the 2nd line in the file that contains the string "Starting"; not a subset of the text starting with the last occurrence of the string "Starting" and ending at the end of the file.
With the : after ERROR marked in red above, I don't see how you got ERROR lines output either. I'm short on time today, (and this hasn't been tested), but try something more like:
exactly as shown above and you got that diagnostic (and you're using a Solaris/SunOS system), try running the script with /usr/xpg4/bin/sh instead of /bin/sh .
---------- Post updated at 03:26 PM ---------- Previous update was at 02:59 PM ----------
when I have given following code it is displaying properly from last occurance 'Starting' to end of file, searching ERROR/WARNING and redirecting it in "Extractfile" also, but line number is displaying wrong in grep. Please advise me.
In your first post you wanted a "before" line (that my awk script stored in the b variable) and 2 "after" lines.
Without "before" line and 3 "after" lines:
and accept ERROR and WARNING in mixed case (not just in all caps). You and I could duplicate this in awk, but it is complex enough that I didn't want to take the time to reinvent what grep already does so well. I thought we just needed to extract the final lines from errlog and feed them into the grep command nes had already supplied.
When I tried the following code in SUNOS systeam for small file it is working fine, but if I am using same commnad for 1000 to 10000 lines of file. following code is not working in Sunos systeam.