This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to use awk and grep -v option to exclude several patterns from several lines

I am trying to use a combination of awk and grep to filter several files and to exclude a couple of patterns. I have several options and I just get error.

My commands that have failed are:

awk '/predicted/{flag=1;next}/detected/{flag=0}flag' $i/result_*.csv | grep "yes" | grep -v "dme" "dps" "ame" "aga" "aae" "api" | awk -F "\t" '{print $14"\t"$6}' - | sort -k1 | uniq > $i"-results-filtered.tsv"

The error "grep: dme: No such file or directory" for each of these "dps" "ame" "aga" "aae" "api".

But when when I run with one variable

awk '/predicted/{flag=1;next}/detected/{flag=0}flag' $i/result_*.csv | grep "yes" | grep -v "dme" | awk -F "\t" '{print $14"\t"$6}' - | sort -k1 | uniq > $i"-results-filtered.tsv"

It works well and exclude all the lines that contain "dme"

Again when I try these:

awk '/predicted/{flag=1;next}/detected/{flag=0}flag' $i/result_*.csv | grep "yes" | grep -v "dme,dps,ame,aga,aae,api" | awk -F "\t" '{print $14"\t"$6}' - | sort -k1 | uniq > $i"-results-filtered.tsv"

awk '/predicted/{flag=1;next}/detected/{flag=0}flag' $i/result_*.csv | grep "yes" | grep -v "dme dps ame aga aae api" | awk -F "\t" '{print $14"\t"$6}' - | sort -k1 | uniq > $i"-results-filtered.tsv"

I get results but no filter

Any help please on how I can modify this to get what I want.

Thanks.

awk grep

1 answer

grep -Fv -e "dme" -e "dps" -e "ame" -e "aga" -e "aae" -e "api"

The -e switch should do the trick.

Thank you. It worked like a charm

Log in to answer this question.