1

I have a tab-delimited file with 9 columns as follows:

1   25555818    T   14  0   0   0   14  0:0:0:14
2   25555819    T   14  7   0   0   7   7:0:0:7
3   25555820    G   13  0   0   13  0   0:0:13:0
4   25555821    A   0   0   0   0   0   0:0:0:0
5   25555822    G   11  0   0   11  0   0:0:0:0
6   25555823    T   11  2   0   0   9   2:0:0:9
7   25555824    T   11  0   0   0   11  0:0:0:11
8   25555825    G   11  5   0   3   3   5:0:3:3

I'd like to keep only rows where there are at least two values over zero in either of columns 5,6,7,8. So in the example above, the rows I want to keep are rows 2,6,8. In other words, if there are at least 3 zeroes in column 5-8, the row should be discarded.

The catch is that column 9 is the product of merging columns 5-8, so it may be used for the the pattern match as well; however, as with before, the pattern is not necessarily 3 consecutive zeroes. There just has to be at least 3 zeroes out of the 4 values.

2

Here is one approach:

awk 'BEGIN{FS="\t"} (($5!=0)+($6!=0)+($7!=0)+($8!=0))>=2'

And a terser variant for the C hackers:

awk -F $'\t' '(!!$5+!!$6+!!$7+!!$8)>=2'

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.