We help IT Professionals succeed at work.

awk question - very simple

Talmash
Talmash asked
on
hi ,

I am using this command :

awk '/TIMEOUT/ {getline;getline;print}' errors_log_07Nov20

this log file was look like :

ENTERING I_1_9
ONLC ERROR at time                 3715: rule txd_in_interrupt: int after error
ONLC ERROR at time                 3751: rule txd_in_interrupt: int after error
******** [90779.66800000001] : Error : SIMULATION FINISHED ON TIMEOUT     ********
Verifier Terminated With 1 Errors.
EXIT from I_1_9

so getting 2 lines will give me the line reporting :
EXIT from <test_name>

the problem :
I added to the log files other lines :

ENTERING I_2_2
******** [90779.66800000001] : Error : SIMULATION FINISHED ON TIMEOUT     ********
DUMP COMPARE : ERROR : desc # 2 from voq2txd not reached fb_like !
DUMP_COMPARE : ERROR missing dump files counter = 1 , not_match dump files counter = 0
EXIT from I_2_2


so I should add "getline"s commands with number I don't know .

mission : I want to getline until reached "EXIT from <test_name>" and print ONLY this line .

A grade for a rapid and accurate answer in addition to 150 points which are absolutly more then its worth .

thanks,

tal

Comment
Watch Question

CERTIFIED EXPERT

Commented:
BEGIN {skip=1}
/ENTERING.*test_name/{ skip=0; }
/EXIT/ {if (skip==0) {print; exit;} }
(skip==0){print}
Commented:
Here's a script that will do the trick

awk '/TIMEOUT/ {while ($1 != "EXIT") getline; print}' error_log_07Nov20

pagerbak
TalmashCEO

Author

Commented:
pagerbak :

excellent !!!!

hoffman : sorry for not using your idea,I didn't now how to write it on the command line in one line , as pager did .

can you explain me how does it works ?

tnx,and "slicha"

tal

Commented:
sure I'd like to explain
if you structure the program a bit it's easy to see

<code>
/TIMEOUT/ {
     while ($1 != "EXIT")  # while first word not EXIT
            getline;       # read the next line
     print                 # print the last read line
     }
</code>

Commented:
sure I'd like to explain
if you structure the program a bit it's easy to see

<code>
/TIMEOUT/ {
     while ($1 != "EXIT")  # while first word not EXIT
            getline;       # read the next line
     print                 # print the last read line
     }
</code>

Commented:
sure I'd like to explain
if you structure the program a bit it's easy to see

<code>
/TIMEOUT/ {
     while ($1 != "EXIT")  # while first word not EXIT
            getline;       # read the next line
     print                 # print the last read line
     }
</code>

TalmashCEO

Author

Commented:
I looked for hoffman explain

CERTIFIED EXPERT

Commented:
awk 'BEGIN {skip=1}/ENTERING.*I_2_2/{skip=0;}/EXIT/{if (skip==0){print;exit;}(skip==0){print}' errors_log_07Nov20

Explore More ContentExplore courses, solutions, and other research materials related to this topic.