LinuxQuestions.org

LinuxQuestions.org (/questions/)
-   Linux - Newbie (https://www.linuxquestions.org/questions/linux-newbie-8/)
-   -   filter rows based on filtering two different columns (https://www.linuxquestions.org/questions/linux-newbie-8/filter-rows-based-on-filtering-two-different-columns-4175551063/)

jenbarbsmith 08-18-2015 01:59 PM

filter rows based on filtering two different columns
 
Hello,
I am trying to print out rows that would match a particular filtering criteria on two columns:
Simple matrix:
sample1 0 0 4
sample2 0 0 10
sample3 0 0 15
sample4 0 0 20
sample5 3 2 3

I would like to print out rows where column 2==3 and column 4 <20.
This will print out the last row only.

is this possible in awk?
I understand how to apply one column filter but how to apply a two column filter:
this works so far;
awk '$4<20 {print $0}' simplematrix.txt

I tried:
awk '$4<20 & $2==3 {print $0}' simplematrix.txt
and I get a syntax error.

Anyone help??

schneidz 08-18-2015 02:08 PM

Code:

awk '$4<20 && $2==3 {print $0}' jenbarbsmith.txt

jenbarbsmith 08-18-2015 02:17 PM

Thanks a bunch! Just found the correct syntax on the web too. Appreciate the fast reply!


All times are GMT -5. The time now is 11:48 PM.