Reporting lines above a particular pattern


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Reporting lines above a particular pattern
# 1  
Old 06-25-2012
Reporting lines above a particular pattern

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

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

the command should display
Code:
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

Moderator's Comments:
Mod Comment Please use code tags, thanks!

Last edited by zaxxon; 06-25-2012 at 06:48 AM.. Reason: code tags, see PM
# 2  
Old 06-25-2012
provide proper input file and the expected output
# 3  
Old 06-25-2012
Hi itkamaraj,

INPUT FILE is

Code:
 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)
Code:
 Startpoint: ff1
               (rising edge-triggered flip-flop clocked by CLK3)
 Endpoint: ff4
               (rising clock gating-check end-point clocked by CLK4)
 VIOL   =  10


Moderator's Comments:
Mod Comment Please use code tags, thanks!

Last edited by zaxxon; 06-25-2012 at 06:49 AM.. Reason: code tags, see PM
# 4  
Old 06-25-2012
Code:
 
$ 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

This User Gave Thanks to itkamaraj For This Post:
# 5  
Old 06-25-2012
Please tell me how its working...
also will this work if there are multiple reports in a file say
Code:
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
Code:
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


Quote:
Originally Posted by itkamaraj
Code:
 
$ 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 

          



also please tell me how this is working
thanks

---------- 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...
Quote:
Originally Posted by itkamaraj
Code:
 
$ 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

Moderator's Comments:
Mod Comment Please use code tags, thanks!


---------- 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

Quote:
Originally Posted by itkamaraj
Code:
 
$ 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


Last edited by zaxxon; 06-25-2012 at 06:51 AM.. Reason: code tags, see PM
# 6  
Old 06-25-2012
Quote:
Originally Posted by dll_fpga
also will this work if there are multiple reports in a file
Why not try it yourself and see?

Quote:
Originally Posted by dll_fpga
which parameter should i modify if i need some more lines before the "path group" filed...
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
# 7  
Old 06-25-2012
Reporting lines above a particular pattern

Hi Itkamraj,

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

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

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

[sed] Finding and sticking the pattern to the beginning of successive lines up to the next pattern

I have a file like below. 2018.07.01, Sunday 09:27 some text 123456789 0 21 0.06 0.07 0.00 2018.07.02, Monday 09:31 some text 123456789 1 41 0.26 0.32 0.00 09:39 some text 456789012 1 0.07 0.09 0.09 09:45 some text 932469494 1 55 0.29 0.36 0.00 16:49 some text 123456789 0 48 0.12 0.15 0.00... (9 Replies)
Discussion started by: father_7
9 Replies

2. Shell Programming and Scripting

How to delete all lines before a particular pattern when the pattern is defined in a variable?

I have a file Line 1 a Line 22 Line 33 Line 1 b Line 22 Line 1 c Line 4 Line 5 I want to delete all lines before last occurrence of a line which contains something which is defined in a variable. Say a variable var contains 'Line 1', then I need the following in the output. ... (21 Replies)
Discussion started by: Soham
21 Replies

3. Shell Programming and Scripting

sed -- Find pattern -- print remainder -- plus lines up to pattern -- Minus pattern

The intended result should be : PDF converters 'empty line' gpdftext and pdftotext?xml version="1.0"?> xml:space="preserve"><note-content version="0.1" xmlns:/tomboy/link" xmlns:size="http://beatniksoftware.com/tomboy/size">PDF converters gpdftext and pdftotext</note-content>... (9 Replies)
Discussion started by: Klasform
9 Replies

4. UNIX for Dummies Questions & Answers

Grep -v lines starting with pattern 1 and not matching pattern 2

Hi all! Thanks for taking the time to view this! I want to grep out all lines of a file that starts with pattern 1 but also does not match with the second pattern. Example: Drink a soda Eat a banana Eat multiple bananas Drink an apple juice Eat an apple Eat multiple apples I... (8 Replies)
Discussion started by: demmel
8 Replies

5. Shell Programming and Scripting

Match Pattern and print pattern and multiple lines into one line

Hello Experts , require help . See below output: File inputs ------------------------------------------ Server Host = mike id rl images allocated last updated density vimages expiration last read <------- STATUS ------->... (4 Replies)
Discussion started by: tigerhills
4 Replies

6. Shell Programming and Scripting

Sed: printing lines AFTER pattern matching EXCLUDING the line containing the pattern

'Hi I'm using the following code to extract the lines(and redirect them to a txt file) after the pattern match. But the output is inclusive of the line with pattern match. Which option is to be used to exclude the line containing the pattern? sed -n '/Conn.*User/,$p' > consumers.txt (11 Replies)
Discussion started by: essem
11 Replies

7. Shell Programming and Scripting

Need one liner to search pattern and print everything expect 6 lines from where pattern match made

i need to search for a pattern from a big file and print everything expect the next 6 lines from where the pattern match was made. (8 Replies)
Discussion started by: chidori
8 Replies

8. UNIX for Dummies Questions & Answers

Matching and reporting near-similar lines in a file

Hi, I have a file with the lines as below: C_10_A05_T7 C_10_A06_SP6 C_10_B05_SP6 C_10_B05_T7 C_10_B01_SP6 C_10_B01_T7 C_12_G07_SP6 C_12_G11_SP6 C_12_G11_T7 C_2_H18_T7 C_2_I02_SP6 C_2_I02_T7 C_2_I13_SP6 C_2_I17_SP6 The four segments of each line are connected by '_' symbols. I... (7 Replies)
Discussion started by: Fahmida
7 Replies

9. Shell Programming and Scripting

sed pattern to delete lines containing a pattern, except the first occurance

Hello sed gurus. I am using ksh on Sun and have a file created by concatenating several other files. All files contain header rows. I just need to keep the first occurrence and remove all other header rows. header for file 1111 2222 3333 header for file 1111 2222 3333 header for file... (8 Replies)
Discussion started by: gary_w
8 Replies

10. Shell Programming and Scripting

counting the lines matching a pattern, in between two pattern, and generate a tab

Hi all, I'm looking for some help. I have a file (very long) that is organized like below: >Cluster 0 0 283nt, >01_FRYJ6ZM12HMXZS... at +/99% 1 279nt, >01_FRYJ6ZM12HN12A... at +/99% 2 281nt, >01_FRYJ6ZM12HM4TS... at +/99% 3 283nt, >01_FRYJ6ZM12HM946... at +/99% 4 279nt,... (4 Replies)
Discussion started by: d.chauliac
4 Replies
Login or Register to Ask a Question