awkfiltervcf-variant-call-format

how its better to filtering a file by using awk with more than two pattern matching?


I want to modify this command and create a command to filter rows with "val" flag and more than 2 "PASS". any suggestion?

this command can work only with one PASS:

awk '{if(($5=="val") && ($0 ~ /PASS/ )) {print $0}}' sample.vcf


Solution

  • Assuming $5 is the flag field:

    awk '{if(($5=="val") && ($0 ~ /^.*PASS.*PASS.*$/ )) {print $0}}' sample.vcf

    BTW {if(($5=="val") && ($0 ~ /PASS/ )) {print $0}} will not match any lines since if $5 == "val" $0 will never ~ /PASS/