Tim
Tim

Reputation: 99398

How to use conditional control flow in awk

I have a file whose content is like:

...
... Precision is ill-defined and being set to 0.0 due to no predicted samples ...
...
Score metric (precision_score): 0.0
...

where the line containing Precision is ill-defined and being set to 0.0 due to no predicted samples may or may not exist, and the line containing Score metric (precision_score): may or may not exist.

I want to use AWK to create a variable precision, and

I wonder how to implement that in awk? Thanks.

Upvotes: 0

Views: 46

Answers (1)

karakfa
karakfa

Reputation: 67467

I'm not how this is going to be used but here is something that can get you started

$ awk --posix -F: '/Precision is ill-defined/{precision="+inf"}
 !precision && /Score metric \(precision_score\)/{precision=$2}
                              END{print "precision: "precision}' file

you can add the full text for the pattern.

gawk doesn't support "inf" by default, you have to set the --posix option.

Upvotes: 1

Related Questions