0
votes

Given a file with data such as

2015-12-24 22:02 12   9.87 feet  High Tide
2015-12-25 03:33 12  -0.38 feet  Low Tide
2015-12-25 06:11 12   Full Moon
2015-12-25 10:16 12  11.01 feet  High Tide
2015-12-25 16:09 12  -1.29 feet  Low Tide

This awk command will return a min value in col 4:

awk 'min=="" || $4 < min {min=$4} END{ print min}' FS="  " 12--December.txt

How do I get it to exclude any line where $4 contains text? I imagine this needs regex but poring over the regex manuals I am lost as to how to do it.

1
poring over regex manuals and you couldn't find how to only match numbers ? I searched awk regex in google and the first result clearly explains how to do it. - user4453924

1 Answers

2
votes

You can use a regular expression comparison on the fourth field as

$4~/[0-9]+/

Test

$ awk '$4~/[0-9]+/ && $4 < min {min=$4} END{print min}' input
-1.29

Note This is a minimised version of the code. You can safely skip some of the statements in the example code as in the test code