unix awk column equal to a variable

I want to print the lines that with two columns equal to a variable, for example, input:

2607s1  NC_000067.6 95.92   49  1   1   3   50  1e-14   84.2
2607s1  NC_000067.6 97.73   44  1   0   7   50  4e-14   84.2
2607s1  NC_000067.6 97.67   43  1   0   8   50  1e-13   75.0

and variables for first and last column:

a="2607s1"; b="84.2"

and using awk command, output:

2607s1  NC_000067.6 95.92   49  1   1   3   50  1e-14   84.2
2607s1  NC_000067.6 97.73   44  1   0   7   50  4e-14   84.2

I have tried the following but not work:

awk -v '$1==$a' && '$10==$b' test_file
cat test_file|awk '$1=="($a)" && $10=="($b)"'
cat test_file|awk '$1==($a) && $10==($b)'
cat test_file|awk '$1=="$a" && $10=="$b"'

Moreover, I am running it in a while loop, so the $a and $b keep changing Please help..


Source: unix

Leave a Reply