Reporting lines above a particular pattern

Below is a typical report
each of the lines represent the fields in the report

component1
component2
<pattern>
..
..
n lines ...
..
VIOL       = 2

the command should display

component1
component2
VIOL       = 2

only if pattern field of the report is "good"

component1 and component 2 will be always in the lines preceding the <pattern> field and the VIOL pattern is after n lines..
Please help

provide proper input file and the expected output

Hi itkamaraj,

INPUT FILE is

 Startpoint: ff1
               (rising edge-triggered flip-flop clocked by CLK3)
 Endpoint: ff4
               (rising clock gating-check end-point clocked by CLK4)
  Path Group: good
  Path Type: min
  Point                                                                                                                  
  ----------------------------------
  clock CLK1 (rise edge)                                                                                       
  clock network delay (propagated)      
VIOL   =  10              

OUTPUT is (as the path group field is good...as mentioned earlier ...if the path group field is any pattern other than good it should not display anything)

 Startpoint: ff1
               (rising edge-triggered flip-flop clocked by CLK3)
 Endpoint: ff4
               (rising clock gating-check end-point clocked by CLK4)
 VIOL   =  10              
 
$ awk '/Path.*good/{a=1}!a{line=line"\n"$0}/VIOL/{if(a){print line"\n"$0}}' input.txt
Startpoint: ff1
(rising edge-triggered flip-flop clocked by CLK3)
Endpoint: ff4
(rising clock gating-check end-point clocked by CLK4)
VIOL = 10 

1 Like

Please tell me how its working...
also will this work if there are multiple reports in a file say

Startpoint: ff1
               (rising edge-triggered flip-flop clocked by CLK3)
 Endpoint: ff4
               (rising clock gating-check end-point clocked by CLK4)
  Path Group: good
  Path Type: min
  Point                                                                                                                  
  ----------------------------------
  clock CLK1 (rise edge)                                                                                       
  clock network delay (propagated)      
VIOL   =  10              



Startpoint: ff5
               (rising edge-triggered flip-flop clocked by CLK6)
 Endpoint: ff7
               (rising clock gating-check end-point clocked by CLK40)
  Path Group: bad
  Path Type: min
  Point                                                                                                                  
  ----------------------------------
  clock CLK1 (rise edge)                                                                                       
  clock network delay (propagated)      
test
VIOL   =  15              




Startpoint: ff90
               (rising edge-triggered flip-flop clocked by CLK3f
 Endpoint: ff46
               (rising clock gating-check end-point clocked by CLK4f)
  Path Group: good
  Path Type: min
  Point                                                                                                                  
  ----------------------------------
  clock CLK1 (rise edge)                                                                                       
  clock network delay (propagated)      
VIOL   =  105              

output should be

Startpoint: ff1
                (rising edge-triggered flip-flop clocked by CLK3)
  Endpoint: ff4
                (rising clock gating-check end-point clocked by CLK4)
VIOL   =  10              
Startpoint: ff90
                (rising edge-triggered flip-flop clocked by CLK3f
  Endpoint: ff46
                (rising clock gating-check end-point clocked by CLK4f)
VIOL   =  105    

---------- Post updated at 03:16 PM ---------- Previous update was at 03:13 PM ----------

which parameter should i modify if i need some more lines before the "path group" filed...

---------- Post updated at 03:38 PM ---------- Previous update was at 03:16 PM ----------

Please give any alternate command to do the same
.......
or pls tell me which parameter should i modify to get more than 2 lines preceding the pattern..lets say 5 lines

Why not try it yourself and see?

In the future, please be considerate of those who decide to volunteer some of their time to help you by providing representative sample input and output data, and stating all the conditions and special cases in your original problem statement. Otherwise, someone will squander their time and expertise on a solution that, due to subsequently-disclosed requirements, will either require refinement or abandonment. This goes both ways; you will also save yourself some time, by not having to post multiple followups requesting further functionality or responding to requests for clarification.

Regards,
Alister

Hi Itkamraj,

I still need to understanding this logic, if you donot mind.

 
awk '/Path.*good/{a=1}!a{line=line"\n"$0}/VIOL/{if(a){print line"\n"$0}}' input.txt

Try this...

$ awk '/Startpoint/{for(i=1;i<5;i++){line=line"\n"$0;getline}}/Path.*good/{a=1}/Path.*bad/{line=""} /VIOL/&& a{a=0;print line"\n"$0;line="";}' input.txt

---------- Post updated at 07:32 PM ---------- Previous update was at 07:28 PM ----------

/Path.*good/{a=1}  -- if line matches this pattern (Path.*good), then set the variable a=1

!a {line=line"\n"$0} --- line variable will not get append when it already have the value as 1

/VIOL/ -- if line matches this pattern (VIOL), then check whether it is good or not ( by checking the if(a) ) and print the line

how can i put the else clause to this command ...
ie :when path is good do this...
else for any path (other than good)....ignore this
ie it may not be bad always...
it can be moderate,bad,typical......etc