I have a file with a lot of rows and columns but the number of columns are not same in all rows. I want to extract all rows having delta value greater than 0.02

Point          Fanout   cap   trans   delta   incr   Path
row1             1       0.02  0.01   0.00     0.03   0.04
row2             2       0.04
row3             1       0.01  0.02    0.04    0.05   0.06
row4                     0.03
row5                           0.04     0.05    0.07  0.07

Can anybody help? How to grep all those rows and corresponding delta value?

  • 1
    Delta values always in the 5th field ?
    – Eng7
    Apr 5 '17 at 9:44
  • 3
    How are your fields defined? Are they tab-separated? Space-separated? For example, how many fields does row2 have? Is it 3 or is it 7 with 4 of those blank? Please edit your question and clarify.
    – terdon
    Apr 5 '17 at 10:09

As pointed out in comments, for a delimiter other than space (i.e tab as seems to be your case) bellow solutions would work ok.
If delimiter is space bellow solutions will not work. You need to clarify what is the real fields separator.

awk -F"\t" '$5>0.02' file
awk -F"\t" 'NR==1{print;next}$5>0.02' file #to keep the header
awk -F"\t" 'NR==1 || $5>0.02' file  #also keeps header as advised in comments
awk -F"\t" 'NR<=2 || $5>0.02' file   #keep header and dashed row bellow header as advised by @Sundeep 

If you are in doubt about the format of the numeric values, you could even try

awk -F"\t" '($5*1)>0.02' file
  • for header: awk 'NR==1 || $5>0.02' or awk 'NR<=2 || $5>0.02' to include the second line with dashes as well
    – Sundeep
    Apr 5 '17 at 9:20
  • This won't work if the file is space-separated. For example, try a row where the only non-empty field is the "point" and the "delta". Awk will think the delta is $2 and skip the row. Unless the OP clarifies how their fields are defined, this isn't going to be easy to answer at all.
    – terdon
    Apr 5 '17 at 10:08
  • @terdon Yeap, good point. Better to clarify this in my answer. Will work with a delimiter other than space, since with single space things will get weird. Apr 5 '17 at 10:40

If what you are trying to process are PrimeTime timing reports for fixing your timing violations or crosstalk noise violations then I would advise you to go for the commands (Tcl) that are provided for by your particular EDA tool.

Reinventing the wheel will not really be the way to go.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.