perl - Awk - Get rows from a file that contain values within ranges described in another file -
i have 2 tab-delimited files formatted similar this:
file 1
a 100 90 pass b 89 80 pass c 79 70 pass d 69 60 fail f 59 0 fail
file 2
randy 80 denis 44 earl 97
i want take values column 2 in file 2 , compare them ranges given between columns 2 , 3 of file 1. want create new file combines data, printing columns 1 , 2 file 2 , columns 1 , 4 file 1:
file 3
randy 80 b pass denis 44 f fail earl 97 pass
i want implement using awk or perl.
you can use awk:
awk 'begin{fs=ofs="\t"} fnr==nr { a[$0] = $2 next } { (i in a) if ($2>=a[i] && $3<=a[i]) print i, $1, $4 }' file2 file1
earl 97 pass randy 80 b pass denis 44 f fail
Comments
Post a Comment