awk Numeric Filters: $3 > 10 and Comparisons
awk treats a field as a number in a numeric context, so $3 > 10 keeps rows whose third column exceeds ten.
Thresholding a metric column, such as failing a build when coverage drops or latency climbs, is a one-line awk numeric filter.
What it does
When a field is compared with a numeric operator (>, <, >=, ==), awk coerces it to a number. A leading numeric prefix is parsed and trailing non-numeric text is ignored, so "12ms" compares as 12. The matching lines run the action (print by default).
Common usage
# rows where column 3 exceeds 10
awk '$3 > 10' metrics.txt
# coverage below 80 percent (fail the gate)
awk '$2 < 80 {print "low:", $0}' coverage.txt
# size column at least 1024
awk '$5 >= 1024 {print $1}' sizes.txt
# exact numeric match
awk '$4 == 200' http.logOperators
| Operator | What it does |
|---|---|
| $3 > 10 | Numeric greater-than |
| $3 < 10 | Numeric less-than |
| $3 >= 10 | Greater-than-or-equal |
| $3 == 10 | Numeric equality |
| $3 != 10 | Numeric inequality |
| $2+0 > 1 | Force numeric context by adding 0 |
In CI
A coverage or latency gate reads as awk -v t=80 '$2 < t {bad=1} END{exit bad}' so the build fails on threshold breach via exit status. Force a number with $2+0 when a field has units or padding that confuse the comparison.
Common errors in CI
If a comparison behaves like string comparison ("9" looks greater than "10"), the field is being treated as text; add 0 to force numeric context ($1+0 > $2+0), which happens when a value has leading zeros or surrounding quotes. A field with a thousands separator like 1,024 parses as 1, so strip the comma with gsub first. Comparing against an unset -v variable treats it as 0.