Reputation: 99398
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
if the line containing Precision is ill-defined and being set to 0.0 due to no predicted samples
exists, set the value of precision
to inf
,
otherwise, if the line containing Score metric (precision_score):
exists, set the value of precision
to the number following Score metric (precision_score):
I wonder how to implement that in awk? Thanks.
Upvotes: 0
Views: 46
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