awk - updating a count depending on values in a file fulfilling criteria specified by a second file -
i have 2 files , want update file new column containing counts of how many times number in $2 of file b fell range of $2 , $3 of file a, when $1 matches in both files.
file a
n01 2000 9000 n01 29000 41000 n01 60000 89000 n05 10000 15000 n80 5000 12000 n80 59000 68000 n80 100000 110000
file b
n01 6000 n01 6800 n01 35000 n05 14000 n80 65000 n80 104000
expected output
n01 2000 9000 2 n01 29000 41000 1 n01 60000 89000 0 n05 10000 15000 1 n80 5000 12000 0 n80 59000 68000 1 n80 100000 110000 1
awk ' fnr==nr{ a[$1,$2] next } { c = 0 for(i in a) { split(i,x,subsep) if(x[1] == $1) { if(x[2] >= $2 && x[2] <= $3) { c++ } } } print $0,c } ' fileb filea
awk
No comments:
Post a Comment