2

I have a text file like this small example:

small example:

chr1    HAVANA  exon    13221   13374
chr1    HAVANA  exon    13453   13670
chr1    HAVANA  gene    14363   29806

I am trying to filter the rows base on the 3rd column. in fact if the 3rd column is gene i will keep the entire row and filter out the other rows. here is the expected output:

expected output:

chr1    HAVANA  gene    14363   29806

I am trying to do that in awk using the following command but the results is empty. do you know how to fix it?

awk '{ if ($3 == 'gene') { print } }' infile.txt > outfile.txt

1 Answer 1

4

Use double quotes in the script:

$ awk '{ if ($3 == "gene") { print } }' file
chr1    HAVANA  gene    14363   29806

or:

$ awk '{ if ($3 == "gene") print }' file

but you could just:

$ awk '$3 == "gene"'
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.