1
$\begingroup$

I have a binary file which looks like this,

Orthogroup  A   B   C   D   E   F
OG0000000   1   1   1   0   0   0
OG0000001   1   1   1   0   0   0
OG0000002   1   1   1   0   0   0
OG0000003   1   1   1   0   0   0
OG0000004   0   0   0   1   1   0
OG0000005   0   0   0   1   1   0
OG0000006   0   0   0   1   1   0
OG0000007   0   0   0   1   1   0
OG0000008   1   0   0   0   0   0
OG0000009   1   0   0   0   0   0
OG0000010   1   0   0   0   0   0

I want to use awk to print the first column if column D and E is 1 and rest is 0.

OG0000004
OG0000005
OG0000006
OG0000007

I tried to do this with individual files of each column using the awk command

awk 'NR==FNR{arr[$0];next} $0 in arr' file1 file2 

but doing this I had to generate multiple files and I thought using a binary file will be a more clean way.

Please Help,

$\endgroup$
1
  • $\begingroup$ It would be more helpful to paste the actual text instead of pictures of it. $\endgroup$ Nov 19, 2021 at 21:31

2 Answers 2

2
$\begingroup$

I would do something like this:

$ cat test.tsv 
groupA  1       1       1       0       0       0
groupB  1       1       0       0       0       0
groupC  1       0       1       0       0       0
groupD  1       1       1       0       0       0
groupE  0       0       0       1       1       1
groupF  0       0       0       1       1       0

$ awk '($5==1 && $6==1 && $2+$3+$4+$7==0){print $1}'
groupF
$\endgroup$
1
  • $\begingroup$ Thank you it worked $\endgroup$
    – ambika
    Nov 19, 2021 at 22:12
2
$\begingroup$

Straightforwardly

awk '$2==0 && $3==0 && $4==0 && $5==1 && $6==1 && $7==0 {print $1}' bin.file

A little spiffier

awk '$5 && $6 && !($2 || $3 || $4 || $7) {print $1}' bin.file
$\endgroup$
1
  • $\begingroup$ Thank you it worked $\endgroup$
    – ambika
    Nov 19, 2021 at 22:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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