I have a tab delimited file like so:
col1 col2 col3 col4
a 5 y:3.2 z:5.1
b 7 r:4.1 t:2.2
c 8 e:9.1 u:3.2
d 10 o:5.2 w:1.1
For each row, I want to output the values in the first and second columns, and the smallest number out of the two values in the third and fourth columns.
col1 col2 min
a 5 3.2
b 7 2.2
c 8 3.2
d 10 1.1
My poor attempt:
awk -F'\t' '{min = ($3 < $4) ? $3 : $4; print $1, $2, min}'
One reason it's incorrect is because the values in the third and fourth columns aren't numbers but strings. I don't know how to extract the number out of the third and fourth columns, the number is always after the colon..
awk
to the rescue!