Download your favorite Linux distribution at LQ ISO.
Go Back > Forums > Linux Forums > Linux - Newbie
User Name
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!


  Search this Thread
Old 08-18-2015, 01:59 PM   #1
LQ Newbie
Registered: Aug 2015
Posts: 2

Rep: Reputation: Disabled
filter rows based on filtering two different columns

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??
Old 08-18-2015, 02:08 PM   #2
LQ Guru
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 5,143

Rep: Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877Reputation: 877
awk '$4<20 && $2==3 {print $0}' jenbarbsmith.txt
Old 08-18-2015, 02:17 PM   #3
LQ Newbie
Registered: Aug 2015
Posts: 2

Original Poster
Rep: Reputation: Disabled
Thanks a bunch! Just found the correct syntax on the web too. Appreciate the fast reply!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
[SOLVED] Converting a file with Rows and Columns to just Columns mphillips67 Linux - Newbie 14 03-05-2014 10:31 AM
[SOLVED] transposing rows to columns wilelucho Programming 6 03-29-2013 08:10 AM
[SOLVED] Creating columns from every 4 rows kbensch Linux - General 7 05-19-2012 11:35 AM
[SOLVED] filtering based on columns AlbertJJ Programming 3 11-13-2010 03:03 AM
rows and columns digitalgravy Linux - General 2 03-16-2004 06:47 PM > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 02:45 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration