识别间隔内的字符串,第 1 部分

identifying strings within intervals, pt 1

我想知道第 3 列是否在第 1 列和第 2 列内,方法是在每行的第 4 列中指定 "yes" 或 "no"。这在 awk 中可行吗?

输入

start end snp-pos region
392   508 410     
100   216 222 
269   388 198 

期望的输出

start  end  snp-pos  region
392    508  410      yes
100    216  222      no
269    388  198      no
$ awk 'NR==1{print;next} {print [=10=], (> && < ? "yes" : "no")}' file
start end snp-pos region
392   508 410 yes
100   216 222 no
269   388 198 no

如果您关心排列的列,您可以通过管道传输到 column -t:

$ awk 'NR==1{print;next} {print [=11=], (> && < ? "yes" : "no")}' file | column -t
start  end  snp-pos  region
392    508  410      yes
100    216  222      no
269    388  198      no

或者我们可以编写稍微多一点的代码并完全在 awk 中处理它,例如:

awk 'NR==1{print;w=match([=12=],$NF)-1;next} {printf "%-*s%s\n", w, [=12=], (> && < ? "yes" : "no")}' file
start end snp-pos region
392   508 410     yes
100   216 222     no
269   388 198     no