Consider a stream of lines piped to awk. Lines are composed of sequence of interleaved field names and field values, like the following example (lines really are much longer with many other attributes listed):
Samples 2978 Min -0.068689 at 1389 Amin 1.0406e-08 at 435 Max 0.0514581 at 1375
Samples 2977 Min -0.100258 at 1293 Amin -1.06743e-08 at 3 Max 0.0989735 at 1282
Samples 2977 Min -0.109783 at 1281 Amin -2.97293e-08 at 10 Max 0.139651 at 1268
Samples 2976 Min -0.116509 at 1269 Amin -1.04306e-09 at 161 Max 0.0985577 at 1255
I’d like to extract a certain value from the strings using it’s name as a guide, for example, Min. If I had a scanf-like function in awk, I’d have at first used ind=index($0, "Min"), then s=substr($0, ind), then sscanf(s,"Min %f", &val) to obtain val. However, I dont have any scanf available in awk.
How can I extract the value by it’s name then?
You go through each field, check for “Min” and then extract the next field
Ruby(1.9+)