2.7 years ago
@Vijay Lakhujani26377
The weird format of your file (if indeed it is in this way) is out of anyone's understanding. But I ll explain how awk
could work here provided a nicely formatted tab separated table
Consider your file (say file.txt) this way, the <tab>
and <space>
symbols are for representation, your actual file will have whitepspace (tabs and spaces) and corresponding positions shown in the file
Bacteroides<space>fragilis<tab>0
Bacteroides<space>fragilis<tab>0
Salmonella<space>enterica<tab>1
Salmonella<space>enterica<tab>1
Salmonella<space>enterica<tab>1
Bacteroides<space>fragilis<tab>0
Now if you say
awk '$2==1{print}' file.txt | wc -l
It may not work, because, by default the field separator which awk
consider here is the first white space it encounters which in this case would be the space Bacteroides <space> fragilis
Hence, you must add a field separator -F
awk -F "\t" '$2==1{print}' file.txt | wc -l
I am not able to Understand input file format. You can use following command to count number of 1 in field 2