include filenames in addition to the rows being filtered with awk

I have the awk command below that is selecting rows in multiple files based on the given criteria. To identify which file the selected rows come from I want to include the filename as part of the rows that are been printed.

awk '{ if($4 > 60*$2 &&$2>10 && $8="genus" && $10 !="unclassified") { print }}' *.tsv > out.txt

1 answer

  • answered 2021-05-03 17:59 karakfa

    $ awk '$4>60*$2 && $2>10 && $8=="genus" && $10!="unclassified" {print FILENAME,$0}' *.tsv > out.txt

    Fixed $8="genus" which is assigning the value to $8 instead of conditioning on it. Your output is probably wrong.