Skip to main content
10 of 10
added 13 characters in body
FelixJN
  • 14.1k
  • 2
  • 36
  • 55

Via awk:

  • Test the first three fields if the conditions are met for all set members. (split fields on ; and test each pair)

  • If so, remember the position of the set in each field. (in array sel)

  • In the second block, run through all fields and keep only the values matching the positions from before.

  • Print only, if any match was found.

    BEGIN {FS=OFS="\t"}
    {
    #select IDs of value sets to be keept
      split($1,a,";")
      split($2,b,";")
      split($3,c,";")
      nsel=0 ; delete sel
      for ( i in a ) {
          if (a[i]+0<-0.5 && b[i]+0>1 && c[i]+0>2) {
          sel[++nsel]=i
          }
      }
    #if any: run through all fields and reselect
      if (nsel) {
          for (i=1 ; i<=NF ; i++) {
              split($i,a,";")
              $i=a[sel[1]]
              for (j=2 ; j<=nsel ; j++) {
                  $i=$i";"a[sel[j]]
              }
          }
      }
    }
    #print only if any matching set was found
    nsel
    
FelixJN
  • 14.1k
  • 2
  • 36
  • 55