I previously posted requesting help with  counting occurrences of a string. I'm now hoping to search for the occurrence of a string within a range of values and print out a similarly formatted file (the ranges below are sorted by the initial number in the range).   500506  genome  71445   71461   0500506  genome  308369  308384  0500506  genome  335450  335533  0500506  genome  425268  425293  0500506  genome  623326  623715  0502289  genome  308370  308384  0502289  genome  335462  335689  0502289  genome  425268  425290  0and I want to get a list showing the range, the number of times I see that range in my file, and which of the line identifiers has that range71445-71461 1 500506308369-308369 1 500506308370-308384 2 500506,502289 335450-335461 1 500506335462-335533 2 500506,502289335534-335689 2 500506,502289425268-425290 2 500506,502289425291-425293 1 500506In the example above, 502289 could be either exactly matching the same range as 500506, or may fall somewhere within that range, or vice versa. Will this be do-able with a simple script? Or should I be using something like a perl script instead?
Searching file based on data range
shell script;awk;search
The following script should be tested on much bigger volume of data (more than 4 lines) to check correct execution this statement if ((A[1]<$3 && $4<=A[2])||(A[1]<=$3 && $4<A[2]))awk '    BEGIN{SUBSEP=-}    {     if (($3, $4) in ids)              ids[$3,$4]=ids[$3,$4] , $1          else              ids[$3,$4]=$1    }     END{  for (rng1 in ids) {              split (rng1,A,SUBSEP)              for (rng2 in ids) {                  split (rng2,B,SUBSEP)                  if ((A[1]<B[1] && B[2]<=A[2])||(A[1]<=B[1] && B[2]<A[2]))                      ids[rng2]=ids[rng2] , ids[rng1]                  }              }          for (rng in ids) {              for (i=1;i<=split(ids[rng],D,,);i++)                  a[D[i]]=1              s=k=              n=0              for (j in a) {                  k=k s j                  s=,                  n++                  }              print rng, n, k              delete a              }     }' formatted.file