LinuxQuestions.org
Register a domain and help support LQ
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 03-15-2012, 05:06 PM   #1
java_girl
LQ Newbie
 
Registered: Mar 2012
Posts: 1

Rep: Reputation: Disabled
compare second column of a file then print the first column of it in a ne fil if true


I have this input in my file.txt

213.236.6.230 58 1435
213.236.6.249 24 1532
213.236.9.58 19 67
213.236.10.80 9 1226
213.236.9.193 3 203

I need to compare if 58 > 10, if it is i will save 213.236.6.230 in file2.txt if not go to the next line and so on. Please help.
 
Old 03-15-2012, 05:25 PM   #2
danielbmartin
Senior Member
 
Registered: Apr 2010
Location: Apex, NC, USA
Distribution: Ubuntu
Posts: 1,057

Rep: Reputation: 283Reputation: 283Reputation: 283
Quote:
Originally Posted by java_girl View Post
I have this input in my file.txt

213.236.6.230 58 1435
213.236.6.249 24 1532
213.236.9.58 19 67
213.236.10.80 9 1226
213.236.9.193 3 203

I need to compare if 58 > 10, if it is i will save 213.236.6.230 in file2.txt if not go to the next line and so on. Please help.
Try this...
Code:
awk '{if ($2 > 10) {print $1}}' $InFile > $OutFile
Daniel B. Martin
 
Old 03-16-2012, 04:50 AM   #3
grail
Guru
 
Registered: Sep 2009
Location: Perth
Distribution: Manjaro
Posts: 7,411

Rep: Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873Reputation: 1873
You can also bypass the "if" as anything outside a pair of {} will be evaluated:
Code:
awk '$2 > 10{print $1}' file > outfile
 
  


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
How to read CSV data and compare the column values and then write them in new file VijayaRaghavanLakshman Linux - Newbie 9 01-26-2012 09:02 PM
how to sort the 2nd column on the basis of first column without repeating the value ? zediok Linux - Newbie 15 12-20-2011 11:48 AM
Compare 1 column bash alancampbell6 Programming 3 08-18-2011 06:19 AM
[Help me, plz!!] Compare string in the column in the file... nightmare520 Linux - Newbie 1 12-04-2009 06:40 AM
Read text file column by column RVF16 Programming 11 05-31-2009 07:16 AM


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

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration