LinuxQuestions.org
Support LQ: Use code LQ3 and save $3 on Domain Registration
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
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!

Notices


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

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

Rep: Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845Reputation: 845
Code:
awk '$4<20 && $2==3 {print $0}' jenbarbsmith.txt
 
Old 08-18-2015, 03:17 PM   #3
jenbarbsmith
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!
 
  


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 11:31 AM
[SOLVED] transposing rows to columns wilelucho Programming 6 03-29-2013 09:10 AM
[SOLVED] Creating columns from every 4 rows kbensch Linux - General 7 05-19-2012 12:35 PM
[SOLVED] filtering based on columns AlbertJJ Programming 3 11-13-2010 04:03 AM
rows and columns digitalgravy Linux - General 2 03-16-2004 07:47 PM


All times are GMT -5. The time now is 11:05 AM.

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