BEGIN{FS=OFS="\t"; fi=1; #read rep1 while (getline0) {#1of2 replicates cover the region sep=0; printf("%s\t%s\t%s\t", $1,$2,$3); for (fi=1;fi<3;fi++){ if ($(5+fi)>0){ id=$1;s=$2;e=$3;ok=0; for (i=1;i<=nid[fi,id];i++){ if ((s<=ends[fi,id,i])&&(e>=begs[fi,id,i])){ if (sep==0){printf("%s",det[fi,id,i]);sep=1}else{ printf("|%s",det[fi,id,i]); } strand=st[fi,id,i]; ok=1; break; } } if (ok==0){print "ERR not found "fi" "$0;} } } printf("\t\t%s\n",strand); } }